Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 running total of numbers
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
baykko




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sat Oct 04, 2008 8:09 pm   Post subject: RE:running total of numbers

Define 'running total'. Total of what? num and 2?
baykko




PostPosted: 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
Insectoid




PostPosted: 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'.
Clayton




PostPosted: 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
Insectoid




PostPosted: 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.
baykko




PostPosted: 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
Insectoid




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
baykko




PostPosted: 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
syntax_error




PostPosted: 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.
Clayton




PostPosted: 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.
[Gandalf]




PostPosted: 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:
code:
put "\t hi"

Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: