WHY NOT WORKING? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

WHY NOT WORKING?

#include <iostream> using namespace std; int main() { int a = 1; while (a > 278) { cout << a; a = a + 5; } }

2nd Nov 2017, 11:23 AM
LoMbaX
LoMbaX - avatar
4 Answers
+ 4
"a" equals 1 so there is no way it will ever be greater than 278. the while loop will not execute and the main will terminate.
2nd Nov 2017, 11:26 AM
seamiki
seamiki - avatar
+ 3
a=a+5; doesn't happen because is inside the while loop that will not run as it checks a to be greater than 278. to do what you want to do you probably have to change line 5 like this: while(a<278){ this way the wile loop will execute continously until the value of a increases above 278 and the program will terminate.
2nd Nov 2017, 11:33 AM
seamiki
seamiki - avatar
+ 1
I understood. Thank you very much.
2nd Nov 2017, 11:35 AM
LoMbaX
LoMbaX - avatar
0
But in fact in a cycle there is a = a + 5
2nd Nov 2017, 11:29 AM
LoMbaX
LoMbaX - avatar