Computer Science Canada running total of numbers |
Author: | baykko [ Sat Oct 04, 2008 8:07 pm ] | ||
Post subject: | running total of numbers | ||
This is what I have so far. It is just the basic program that prints the numbers -100 to 100. However, I need to have a running total of these numbers as they print.
I have tried placing totalnum+=num in various places...I get 0 as the final answer, but it does not print as a running total, and the numbers get messed up and just go in random places. |
Author: | Insectoid [ Sat Oct 04, 2008 8:09 pm ] |
Post subject: | RE:running total of numbers |
Define 'running total'. Total of what? num and 2? |
Author: | baykko [ Sat Oct 04, 2008 8:11 pm ] |
Post subject: | Re: running total of numbers |
as the numbers -100 to 100 print, there will be a total of the numbers that changes as each number is printed, so first it adds -100 and -99, and so on |
Author: | Insectoid [ Sat Oct 04, 2008 8:15 pm ] | ||
Post subject: | RE:running total of numbers | ||
Use a reverse for loop.
Hint: use 'x' with your variable 'num'. |
Author: | Clayton [ Sun Oct 05, 2008 9:25 am ] | ||
Post subject: | RE:running total of numbers | ||
Or just use a regular one...
|
Author: | Insectoid [ Sun Oct 05, 2008 9:39 am ] |
Post subject: | RE:running total of numbers |
Woops... Go with Clayton's idea, it'll work. Mine won't. |
Author: | baykko [ Sun Oct 05, 2008 7:40 pm ] |
Post subject: | Re: running total of numbers |
well i've also used the for loop the problem is getting it to show the running total when i put total+=x, it just says varible has no value |
Author: | Insectoid [ Sun Oct 05, 2008 7:42 pm ] |
Post subject: | RE:running total of numbers |
you need total := 0 at the top, and x has to be the same case as the one used to declare the for loop. |
Author: | baykko [ Sun Oct 05, 2008 7:45 pm ] | ||
Post subject: | Re: running total of numbers | ||
Now it somewhat works... but i want the numbers -100 to 100 to be printed left to right... but right now they just stay on one spot
|
Author: | syntax_error [ Mon Oct 06, 2008 12:31 am ] | ||
Post subject: | Re: running total of numbers | ||
wonderful thing called
edit: code tags. |
Author: | Clayton [ Mon Oct 06, 2008 8:58 am ] |
Post subject: | RE:running total of numbers |
Get rid of the locates, that is what is causing your numbers to stay in one spot. |
Author: | [Gandalf] [ Mon Oct 06, 2008 4:05 pm ] | ||
Post subject: | RE:running total of numbers | ||
syntax_error, escape characters use the backslash, not the forward slash:
![]() |