
-----------------------------------
baykko
Sat Oct 04, 2008 8:07 pm

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.


var num : int := -100
loop
    delay (50)
    put num : 5 ..
    num += 2
    exit when num = 102
end loop



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.

-----------------------------------
Insectoid
Sat Oct 04, 2008 8:09 pm

RE:running total of numbers
-----------------------------------
Define 'running total'. Total of what? num and 2?

-----------------------------------
baykko
Sat Oct 04, 2008 8:11 pm

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

-----------------------------------
Insectoid
Sat Oct 04, 2008 8:15 pm

RE:running total of numbers
-----------------------------------
Use a reverse for loop. 


for decreasing x: -100, 100
    %stuff in here
end for


Hint: use 'x' with your variable 'num'.

-----------------------------------
Clayton
Sun Oct 05, 2008 9:25 am

RE:running total of numbers
-----------------------------------
Or just use a regular one...

for x : -100 .. 100
    %stuff
end for

-----------------------------------
Insectoid
Sun Oct 05, 2008 9:39 am

RE:running total of numbers
-----------------------------------
Woops... Go with Clayton's idea, it'll work. Mine won't.

-----------------------------------
baykko
Sun Oct 05, 2008 7:40 pm

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

-----------------------------------
Insectoid
Sun Oct 05, 2008 7:42 pm

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.

-----------------------------------
baykko
Sun Oct 05, 2008 7:45 pm

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

var total : int := 0
for x : -100 .. 100 by 2
    delay (50)
    locate (10, 1)
    put x : 5 ..
    total += x
    locate (20, 30)
    put total
end for


-----------------------------------
syntax_error
Mon Oct 06, 2008 12:31 am

Re: running total of numbers
-----------------------------------
wonderful thing called 
put " "
OR
put "/t", total [etc..]


edit: code tags.

-----------------------------------
Clayton
Mon Oct 06, 2008 8:58 am

RE:running total of numbers
-----------------------------------
Get rid of the locates, that is what is causing your numbers to stay in one spot.

-----------------------------------
[Gandalf]
Mon Oct 06, 2008 4:05 pm

RE:running total of numbers
-----------------------------------
syntax_error, escape characters use the backslash, not the forward slash:
put "\t hi"
:)
