Computer Science Canada Issue with simple number counting application |
Author: | sheepo39 [ Mon Dec 14, 2009 6:18 pm ] | ||
Post subject: | Issue with simple number counting application | ||
I'm working on a number counting application and the code is
Say, I choose one, and ten, The output is First number: 1 Number: 2 Number: 3 Number: 4 Final number: 5 However, as you can see, it stops at five instead of ten, I don't get what is causing this. Any ideas on how to fix this? Thanks, John |
Author: | DemonWasp [ Mon Dec 14, 2009 7:20 pm ] |
Post subject: | RE:Issue with simple number counting application |
You're incrementing 'lesserNumber' in addition to 'numberOfCounts' (see your for() line...), which is what you seem to have intended. This makes the third condition in your loop true because ( 5 == 10 - 5) is true. Your loop line should declare and initialise numberOfCounts before the first semicolon; next it should check that numberOfCounts < greaterNumber; then it should numberOfCounts++ . |