There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:What exact problem are you having? Does this compile? Does it crash? Does it give the wrong total?
It's hard to help you if you don't TellTheDetails (<--click that).
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joanne
awww...you gave it away.Joanne Neal wrote:Your while loop condition checks the value of currentValue, but that value never changes, so you will either never enter that loop or never exit from it.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:
awww...you gave it away.Joanne Neal wrote:Your while loop condition checks the value of currentValue, but that value never changes, so you will either never enter that loop or never exit from it.
Hayles Berry wrote:I don't quite understand why the currentValue never changes at the moment though, as I thought that was being in-putted by the user.
Joanne
Joanne Neal wrote:
Which line of code gets input from the user ?
Does that line of code ever get called once your while loop starts ?
Hayles Berry wrote:My guess is maybe my 'sum = sum + currentValue;' line is possibly in the wrong place? ^^;;
Joanne
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joanne Neal wrote:
Hayles Berry wrote:My guess is maybe my 'sum = sum + currentValue;' line is possibly in the wrong place? ^^;;
How many times does the message
in the while loop, sum is
get printed. Does that give you a hint as to what your problem is ?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Hayles Berry wrote:Well I've made it so that message is now only printed once,
Joanne
fred rosenberger wrote:So in the above, line 2 is looped as the body of your while. Lines 3-5 are NOT part of any loop. They are run exactly once (although it is only line 4 that does anything).
Joanne
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |