Computer Science Canada

Beginner Turing Problem- variables???

Author:  mattpk [ 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 Smile
code:
[syntax="Turing"]Code Here[/syntax]

Author:  dc116 [ 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

Author:  dc116 [ 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.

Author:  mattpk [ Fri Dec 19, 2008 5:24 pm ]
Post subject:  RE:Beginner Turing Problem- variables???

Thank you dc116!

Author:  Sam_sam [ 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

Author:  mattpk [ 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


: