Author |
Message |
baykko
|
Posted: 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.
Turing: |
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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sat Oct 04, 2008 8:09 pm Post subject: RE:running total of numbers |
|
|
Define 'running total'. Total of what? num and 2? |
|
|
|
|
![](images/spacer.gif) |
baykko
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sat Oct 04, 2008 8:15 pm Post subject: RE:running total of numbers |
|
|
Use a reverse for loop.
code: |
for decreasing x: -100, 100
%stuff in here
end for
|
Hint: use 'x' with your variable 'num'. |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Sun Oct 05, 2008 9:25 am Post subject: RE:running total of numbers |
|
|
Or just use a regular one...
Turing: | for x : -100 .. 100
%stuff
end for |
|
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
baykko
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
baykko
|
Posted: 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
Turing: | 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
|
|
|
|
|
|
![](images/spacer.gif) |
syntax_error
![](http://compsci.ca/v3/uploads/user_avatars/196798963948cf16794b6e5.jpg)
|
Posted: Mon Oct 06, 2008 12:31 am Post subject: Re: running total of numbers |
|
|
wonderful thing called code: |
put " "
OR
put "/t", total [etc..]
|
edit: code tags. |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: 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:
![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
|