0
How to fix the bug?
int x; int y; cin>>x; cin>>y; if( x < 1000){ while ( x < 999) { x = x + y; cout << x << endl; } } When I give x and y's values like x=50,y=20 it prints 70 to 1010 . But it must have printed 70 to 980 . What's wrong ??
8 Answers
+ 3
Check this if its what you want::
https://code.sololearn.com/c0zxE3PKlVQP/?ref=app
+ 2
When value reaches 990 it checks if x<999 since it is loop runs again and adds 20 more ,which results in 1010 and you exit out of the while and if loop after that
,Perhaps you may want to check your calculations again
+ 2
+ 2
Ok good, can i delete the code now?
0
Yeah i was mistaken.. it prints from 70 to 990 . But it shouldn't print 1010 cause 990 is less than 1000.
0
Now what should i do to not include 1010 when x=990? . Plus its uncanny to me because when i write the code that i learned from "while loop" part , it doesn't print 1010 while there's no difference between what Sololearn has write and my own programđ
0
That's exactly what I needđ€
0
Feel free broâ„ïž