0

What should i do in last line

#include <iostream> using namespace std; int main() { int num; cout<<"Institute Timer.\n"; cin>>num; while (num >= 0) { cout << "Number: " << num << endl; num = num -1; if(num==0){ cout<<"Cookover!"<<endl; } } return 0; } if you compile it, it will say (when you write 5) 5 4 3 2 1 cookover! 0 but i want this program to say 5 4 3 2 1 0 cookover! what should i do?

23rd Jul 2017, 6:42 AM
이병주
이병주 - avatar
4 Answers
+ 11
Or you can do if (num == -1) //crappy fix tho.
23rd Jul 2017, 7:25 AM
Hatsy Rei
Hatsy Rei - avatar
+ 9
move cookover outside the loop?
23rd Jul 2017, 7:03 AM
jay
jay - avatar
+ 6
do: while (num > 0) { instead of: while (num >= 0) { (Line 9)
23rd Jul 2017, 6:54 AM
Jordan Chapman
Jordan Chapman - avatar
+ 1
You don't need the if loop. remove the if loop and close the while loop before cout << "cookover" You are set!
25th Jul 2017, 11:40 AM
Manish Madhukar