+ 1

Trying to make in countdown from 3 2 1 0

#include <iostream> using namespace std; int main() { int seconds; cin>>seconds; while (seconds <= 5){ seconds--; } return 0; }

17th Sep 2021, 10:24 AM
Mando
Mando - avatar
8 Respuestas
+ 4
You can do something like this: while (seconds >= 0){ cout<<seconds<<endl; seconds--; }
17th Sep 2021, 10:37 AM
Rupali Haldiya
Rupali Haldiya - avatar
+ 1
If you want to make a delay between each second so it won't print instantly- read about the thread and chrono modules in C++.
17th Sep 2021, 11:38 AM
Yahel
Yahel - avatar
0
Didnt work
17th Sep 2021, 10:43 AM
Mando
Mando - avatar
0
Mando can you please describe your problem a little bit more..?
17th Sep 2021, 10:46 AM
Rupali Haldiya
Rupali Haldiya - avatar
0
rupali Create a timer program that will take the number of seconds as input, output the remaining time and countdown to 0. You need to output every number, including 0. Sample Input 5 Sample Input 5 4 3 2 1 0
17th Sep 2021, 10:47 AM
Mando
Mando - avatar
17th Sep 2021, 10:51 AM
Rupali Haldiya
Rupali Haldiya - avatar
0
Thanks
17th Sep 2021, 10:52 AM
Mando
Mando - avatar
0
#include <iostream> using namespace std; int main() { int seconds; cin >> seconds; if(seconds == 4){ while(seconds){ seconds--; cout << seconds << endl; } } else{ cout << "invalid input"; } return 0; } PS: if you want to count down from all numbers just remove the if statment
17th Sep 2021, 11:04 AM
ox titanium
ox titanium - avatar