0

There is an error happening with my practice

When I can't figure out the answer on my own, I try to learn from the answer but the answer is producing an infinite loop instead of creating a countdown timer. I am doing the majority of the work on a tablet and then I use my phone when I'm stuck. I used the answer code in the code playground and it ran with out producing an infinite loop. How ever I am also having an infinite loop error with the countdown ending project.

13th Mar 2022, 5:58 AM
Tyler Boone
Tyler Boone - avatar
4 ответов
+ 3
The while...loop's body consists of two lines, for this reason, you need to wrap the loop body inside curly brackets. Without the curly brackets, only one line following the loop construct will be executed (the line that prints <seconds> variable). The line(s) after will not be considered as part of loop body and that's why you got an infinite loop, because the line where <seconds> is decremented isn't gerting processed. while( seconds >= 0 ) { cout << seconds << endl; seconds--; }
17th Mar 2022, 5:12 AM
Ipang
+ 1
Show us your code? Oo"
13th Mar 2022, 8:28 AM
SoloProg
SoloProg - avatar
+ 1
Ok that's what I wasn't noticing. Thank you
17th Mar 2022, 3:27 PM
Tyler Boone
Tyler Boone - avatar
0
#include <iostream> using namespace std; int main() { int seconds; cin>>seconds; //your code goes here while(seconds>=0) cout<<seconds<<endl; seconds--; return 0; }
17th Mar 2022, 1:41 AM
Tyler Boone
Tyler Boone - avatar