Beginner Turing Problem- variables???
Author |
Message |
mattpk
|
Posted: Fri Dec 19, 2008 4:34 pm Post subject: Beginner Turing Problem- variables??? |
|
|
Hi guys i am new to this forum I got interested in turing from my older brother.
I am 11, so please when you explain this to me i understand.
My brother challenged me to make a program that lets you get the person's marks and find the average. Simple enough, but very complicated now!
Turing: |
var numberofmarks, countt, totallmark, markk, average : int
begin
put "How many marks would you like to to in for your average?"
get numberofmarks
loop
countt := countt + 1
put "What is mark ", countt, "?"
get markk
totallmark := markk + totallmark
markk := 0
exit when countt = numberofmarks
end loop
put "Your average is ", totallmark / countt, "!"
end
|
I run this, but then the program becomes finished after the user gives the variable numberofmarks. The loop isn't done for some reason, and the things after the loop aren't either.
Mod Edit: Remember to use syntax tags! Thanks code: | [syntax="Turing"]Code Here[/syntax] |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
dc116
|
Posted: Fri Dec 19, 2008 5:15 pm Post subject: RE:Beginner Turing Problem- variables??? |
|
|
You have to first set countt and totallmark to 0
code: |
countt := 0
totallmark := 0
|
|
|
|
|
|
|
dc116
|
Posted: Fri Dec 19, 2008 5:21 pm Post subject: RE:Beginner Turing Problem- variables??? |
|
|
Just to add something.
You don't need the "average" variable, notice how you didn't even use it in your program.
Also the program might be easier to understand if you use a counted loop. |
|
|
|
|
|
mattpk
|
Posted: Fri Dec 19, 2008 5:24 pm Post subject: RE:Beginner Turing Problem- variables??? |
|
|
Thank you dc116! |
|
|
|
|
|
Sam_sam
|
Posted: Fri Dec 19, 2008 9:50 pm Post subject: Re: Beginner Turing Problem- variables??? |
|
|
WOW!! I am impressed.. someone your age! That is awsome
Anyway.. here is your finished and working code:
Turing: | var numberofmarks, markk : int
var countt,totallmark:int :=0
begin
put "How many marks would you like to to in for your average?"
get numberofmarks
loop
countt := countt + 1
put "What is mark ", countt, "?"
get markk
totallmark := markk + totallmark
markk := 0
exit when countt = numberofmarks
end loop
put "Your average is ", totallmark / countt, "!"
end
|
|
|
|
|
|
|
mattpk
|
Posted: Sat Dec 20, 2008 10:14 am Post subject: RE:Beginner Turing Problem- variables??? |
|
|
Thx, Sam_Sam, my brother inspired me and i have some practice coding from GML, anyone can do it if they put their mind to it |
|
|
|
|
|
|
|