+ 1
How to print all scanned inputs from user
Hi, i want to ask why my output doesn't display all the numbers the user inputs, instead it just displays the later input. In example the user inputs : 2 3 5 Then the output should be : Case #1: 1 You 2 You 3 Me Case #2: 1 You 2 You 3 Me 4 You 5 Me Instead the output is : Case #1: 1 You 2 You 3 Me 4 You 5 Me Case #2: 1 You 2 You 3 Me 4 You 5 Me https://code.sololearn.com/cLD7G3DaWF8r/?ref=app
1 Answer
0
There is two solutions:
#1: scan number and do stuff in one loop
#2: scan numbers to array and then use it
In the firtst loop you are rewriting your variable in every step. So final value is last number that user entered. And that value is used in the second loop which prints all cases for this final value. In your case it was 5.