use std::thread;
use std::time::Duration;
fn countdown(seconds: u32) {
println!("Total time: {} seconds", seconds);
let mut remaining = seconds;
while remaining > 0 {
thread::sleep(Duration::from_secs(1)); // Sleep for 1 second
remaining -= 1;
println!("Time remaining: {} seconds", remaining);
}
}
fn main() {
let sec = 5;
countdown(sec);
}
/*
run:
Total time: 5 seconds
Time remaining: 4 seconds
Time remaining: 3 seconds
Time remaining: 2 seconds
Time remaining: 1 seconds
Time remaining: 0 seconds
*/