0

Why isn't my code printing 5 and going up 1 each time until it is 10?

https://code.sololearn.com/c7tqnXsN8OOr/?ref=app

26th Jul 2017, 9:06 PM
Whitehat
Whitehat - avatar
2 Antworten
+ 1
I've spotted two problems: 1) You've declared int 'a' twice. Once at the top (line 4) and again during the while loop (line 10). You need to remove the 'int' declaration on line 10. Once you do that, you'll notice it prints: 5 5 6 7 8 9 That brings us to the second problem: 2) You want <= instead of just <. Otherwise, the loop will not print out 10. It would stop at 9, and once a becomes 10, the loop would cease to run with just "<". OR you could make it a < 11, though I prefer the first option.
26th Jul 2017, 9:21 PM
Christian Barraza
Christian Barraza - avatar