Trouble understanding While statement excercise | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Trouble understanding While statement excercise

I was completing the While statement practice for C++. I got the correct answer but I can’t figure out why it’s correct. According to the code, shouldn’t this have put out other numbers too? Isn’t it basically taking any number less than 20 and adding 3 to it? So shouldn’t that result in more than just multiples of 3? This is probably super stupid but I’m brand new at this. https://code.sololearn.com/cn3XGh5mp4F2/?ref=app

12th Jan 2022, 10:38 PM
Jonathan Patterson
4 Answers
+ 2
It's not taking any number because you assigned it to 3 and 3 does not equal more then
12th Jan 2022, 10:44 PM
Ion Kare
Ion Kare - avatar
0
Oh I see. So instead of it adding 3 to every number under 20, its starting with 3, then adding 3 every time until that number is over 20. Got it. Thanks, mate. I feel dumb but that makes so much more sense now.
12th Jan 2022, 10:48 PM
Jonathan Patterson
0
Yup try changing 20 to 100 and see what happens
12th Jan 2022, 10:49 PM
Ion Kare
Ion Kare - avatar
0
And change 3 to 1 and see what happens , I suggests re writing the code from scratch till you understand it change the stuff around
12th Jan 2022, 10:50 PM
Ion Kare
Ion Kare - avatar