
-----------------------------------
mattpk
Fri Dec 19, 2008 4:34 pm

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!




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 :) [syntax="Turing"]Code Here[/syntax]

-----------------------------------
dc116
Fri Dec 19, 2008 5:15 pm

RE:Beginner Turing Problem- variables???
-----------------------------------
You have to first set countt and totallmark to 0


countt := 0
totallmark := 0


-----------------------------------
dc116
Fri Dec 19, 2008 5:21 pm

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
Fri Dec 19, 2008 5:24 pm

RE:Beginner Turing Problem- variables???
-----------------------------------
Thank you dc116!

-----------------------------------
Sam_sam
Fri Dec 19, 2008 9:50 pm

Re: Beginner Turing Problem- variables???
-----------------------------------
WOW!! I am impressed.. someone your age! That is awsome

Anyway.. here is your finished and working code:

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
Sat Dec 20, 2008 10:14 am

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
