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

Username:   Password: 
 RegisterRegister   
 New to Turing : Accumulator question
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kira




PostPosted: Sat Oct 20, 2007 9:27 pm   Post subject: New to Turing : Accumulator question

hi, I'm new to turing. I just wanted to know if there's a way I can use an accumulator and add numbers when I cls a screen. Everytime i typed a number in...it doesn't add the number before(after I want to try again)....is there a way I can change it..so it could add? Here is the commands I used

var reply : string
loop
cls
locate (4, 1)
var GrossPay, total : real
total := 0
locate (1, 1)
put "Enter the value of Gross Pay"
locate (2, 1)
put "$"
locate (2, 2)
get GrossPay
total := GrossPay + total
put "It totalled $", total : 5 : 2, " dollars."
put "Do you want to try again? Answer y or n " ..
get reply
exit when reply = "n"
loop
exit
end loop
end loop
Sponsor
Sponsor
Sponsor
sponsor
Zampano




PostPosted: Sat Oct 20, 2007 9:47 pm   Post subject: Re: New to Turing : Accumulator question

Every time you reenter the loop, you are redeclaring total as 0. Therefore your program is getting the gross pay, adding it to the total, making the total 0 again, and doing again and again. Put total:=0 outside the loop. Also, declare your variables at the beginning of the program as a manner of good programming habit.
Kira




PostPosted: Sat Oct 20, 2007 9:50 pm   Post subject: RE:New to Turing : Accumulator question

Thank You so much!
Zampano




PostPosted: Sat Oct 20, 2007 9:50 pm   Post subject: Re: New to Turing : Accumulator question

Sure.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: