+ 1
C++ while loop please help! I can't run it properly. I'm also new to programming.
The task is to write a program that inputs 5 integer and print the smallest value using while loop. https://code.sololearn.com/cqS5zuuP8oMx/?ref=app https://code.sololearn.com/cqS5zuuP8oMx/?ref=app
8 odpowiedzi
+ 2
Jayakrishna🇮🇳 :D
not as fast as you could think...
I've just see this thread while refreshing most recent posts list.
I've first passed as Jessica Zarate doesn't post its code, then new refresh, coming to see what was posted and see code...
I've hesitate a few, then studying code and finally posted only 5 minutes before you ;)
+ 1
you use num for input, and you increment it as it was a counter (but you reset value at each iteration)...
you must at least use a separate counter variable initialized to zero, and check for it in your while loop condition instead of num (and obviously increment it rather than num).
+ 1
you must also test for counter<max instead of <= or initialize counter at one instead if zero...
+ 1
Thank you for the help visph ! I'll make them separate.
+ 1
num= stoi(input);
num++;
Here, if i enter 5 or greater number then by num++, loop stops here because num<=5 becomes false.
You shloud use other variable for counter here.
For ex: count++;
+ 1
Thank you too for pointing that out sir Jayakrishna🇮🇳
+ 1
@visph is fast. its already answered. I didn't see.
Jessica Zarate You're welcome..
+ 1
visph still you are 1st..
I mean only ,it is answered already before me. Upon refresh after my post i seen it. If i see it before, i didn't post. It seems duplicate now..