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.
4 Respostas
+ 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--;
}
+ 1
Show us your code?
Oo"
+ 1
Ok that's what I wasn't noticing. Thank you
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;
}