Computer Science Canada New to Turing : Accumulator question |
| Author: | Kira [ 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 |
|
| Author: | Zampano [ 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. |
|
| Author: | Kira [ Sat Oct 20, 2007 9:50 pm ] |
| Post subject: | RE:New to Turing : Accumulator question |
Thank You so much! |
|
| Author: | Zampano [ Sat Oct 20, 2007 9:50 pm ] |
| Post subject: | Re: New to Turing : Accumulator question |
Sure. |
|