
-----------------------------------
kznavy
Thu Feb 11, 2010 8:45 pm

Math quiz program
-----------------------------------
What is it you are trying to achieve?
Create a program that tests you with basic arithmetic (addition & subtraction). It will give you the option of how many questions, difficulty, and the operatino (addition or subtraction)


What is the problem you are having?
I am getting "syntax errors" (i do not know why because end is spelled right :S) also i do not know how to put the user back to the beginning after they are done (y/n question maybe)


Describe what you have tried to solve this problem
Everything I currently know

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
setscreen ("graphics:600;600")
var nq,n1,n2,n3,n4,n5,n6,x,y,o,add,sub,s,user : int
add := +
sub :=  - 
s := 0
var dif,correct,wrong : string
correct := "*CORRECT*" 
wrong := "-WRONG-"


%Easy 
randint (n1,1,5)
randint (n2,5,10)
%Easy 

%Medium
randint (n3,10,15)
randint (n4,15,20)
%Medium

%Hard
randint (n5,20,25)
randint (n6,25,30) 
%Hard

Text.LocateXY (200,600)
put "Please specify what version of Turing you are using
4.1.1

-----------------------------------
Zren
Thu Feb 11, 2010 9:26 pm

RE:Math quiz program
-----------------------------------
Take all your code, ident it. And look at the last line of code. It shouldn't be indented (meaning you forgot a closing end __ somewhere).

Hint: The syntax error is being called since it's attempting to close a statement of a different type. Like so:

loop
...
end if

-----------------------------------
kznavy
Thu Feb 11, 2010 9:36 pm

RE:Math quiz program
-----------------------------------
how do i ident D:

-----------------------------------
Zren
Thu Feb 11, 2010 9:48 pm

Re: Math quiz program
-----------------------------------
F2 or click the big grey button---v


Oh man there's more once you finish that...

get o
Returns a string so your if conditions would need to be "1" instead of 1.

   sub := -
What's your logic with this? Positive or Negative? Integers require a number, not an     if user = y, s, x then
This won't work because of the above. It also isn't a boolean comparison to begin with. Both sides of the comparison must be numbers, the comma is used to join strings together. Though it isn't even usable inside an if statement either. Basically you need to do this mathematically.

Here's a hint how you could posibly salvage your code though.

y + (1)*x
= y + 1x
= y + x

y + (-1)*x
= y + -1x
= y - x

-----------------------------------
Turing_Gamer
Thu Feb 11, 2010 10:03 pm

Re: Math quiz program
-----------------------------------
If you want, you can have random equations like so...

for i : 1 .. 10
    put "Question " + intstr (i)
    Num1 := Rand.Int (1, 50)
    Num2 := Rand.Int (1, 50)
    equation := Rand.Int (1, 2)
    if equation = 1 then
         symbol := +
    else
         symbol := -
    end if
    put Num1 + " " + symbol + " " + Num2 + " ="
    get reply
    %Boolean logic determining if  operation match reply then correct, else incorrect
    %Reset code
end for

This isn't a correct way to do it, just a hint of what to do.

-----------------------------------
kznavy
Thu Feb 11, 2010 10:11 pm

RE:Math quiz program
-----------------------------------
Can i get THE correct way to do it, i am confused =_=

-----------------------------------
Zren
Thu Feb 11, 2010 10:15 pm

RE:Math quiz program
-----------------------------------
Did you find the missing end __ statement? And if so, post your updated code.

-----------------------------------
kznavy
Fri Feb 12, 2010 6:43 pm

RE:Math quiz program
-----------------------------------
Alright i got it 
now i have another problem: It will not run the questions the number of times the user inputs. It will only run 1 question and end after it is answered.

CODE: 
_____________________________
setscreen ("graphics:600;600")
var nq, n1, n2, n3, n4, n5, n6, x, y, o, user, ccounter, wcounter,counter : int
nq := 0
ccounter := 0
wcounter := 0
counter := 0

var dif, correct, wrong : string
correct := "*CORRECT*"
wrong := "-WRONG-"


%Easy
randint (n1, 1, 5)
randint (n2, 5, 10)
%Easy

%Medium
randint (n3, 10, 20)
randint (n4, 15, 25)
%Medium

%Hard
randint (n5, 20, 40)
randint (n6, 25, 45)
%Hard

Text.LocateXY (200, 600)
put "[WELCOME TO MATH PRACTICE] V.1"

put "How many questions would you like?"
    get nq

loop
counter += 1
    Text.LocateXY (0, 550)
    
    put "What difficulty would you like? (easy,medium,hard)"
    get dif

    if dif = "easy" then
        x := n1
        y := n2

    end if
    if dif = "medium" then
        x := n3
        y := n4

    end if
    if dif = "hard" then
        x := n5
        y := n6
    end if

    Text.LocateXY (0, 500)
    put "What operation would you like to practice? (add = 1,sub = 0,multi = 2)"
    get o

    if o = 1 then
        Text.LocateXY (0, 400)
        put "[ADDITION] Please complete"
        put x, " + ", y
        get user
        if user = x + y then
            put correct
            ccounter := ccounter + 1
        else
            put wrong
            wcounter := wcounter + 1
            exit when counter = nq  
        end if 
        end if

        if o = 0 then
            Text.LocateXY (0, 400)
            put "[SUBTRACTION] Please complete"
            put y, " - ", x
            get user
            if user = y - x then
                put correct
                ccounter := ccounter + 1
            else
                put wrong
                wcounter := wcounter + 1
                put counter
                exit when counter = nq  
                 
            end if 
            end if
            
          
            Text.LocateXY (300, 300)
            put "NUMBER OF QUESTIONS RIGHT"
            put ccounter
            Text.LocateXY (300, 250)
            put "NUMBER OF QUESTIONS WRONG"
            put wcounter

        end loop 
____________________

-----------------------------------
TerranceN
Fri Feb 12, 2010 7:03 pm

RE:Math quiz program
-----------------------------------
Are you SURE it ends?

It is actually asking the user what difficulty they would like again, but it did not clear what was there before, so its hard to see that it is waiting for input. In fact, if your user's last question is correct then it goes on forever.

-----------------------------------
SNIPERDUDE
Fri Feb 12, 2010 7:44 pm

RE:Math quiz program
-----------------------------------
For future reference, syntax highlighting for code makes it easy to read.

 % code here . . . [/code]

-----------------------------------
kznavy
Fri Feb 12, 2010 7:51 pm

RE:Math quiz program
-----------------------------------
 
setscreen ("graphics:600;600") 
var nq, n1, n2, n3, n4, n5, n6, x, y, o, user, ccounter, wcounter,counter : int 
nq := 0 
ccounter := 0 
wcounter := 0 
counter := 0 

var dif, correct, wrong : string 
correct := "*CORRECT*" 
wrong := "-WRONG-" 


%Easy 
randint (n1, 1, 5) 
randint (n2, 5, 10) 
%Easy 

%Medium 
randint (n3, 10, 20) 
randint (n4, 15, 25) 
%Medium 

%Hard 
randint (n5, 20, 40) 
randint (n6, 25, 45) 
%Hard 

Text.LocateXY (200, 600) 
put "

-----------------------------------
SNIPERDUDE
Fri Feb 12, 2010 8:06 pm

Re: Math quiz program
-----------------------------------
The best way to make it readible is to indent each block of code accordingly.  Although this can be done in Turing with the tab key, you'd have to do it manually here using the space key (1 tab indent = 4 spaces setscreen ("graphics:600;600")
var nq, n1, n2, n3, n4, n5, n6, x, y, o, user, ccounter, wcounter,counter : int := 0

var dif, correct, wrong : string
correct := "*CORRECT*"
wrong := "-WRONG-"


%Easy
randint (n1, 1, 5)
randint (n2, 5, 10)
%Easy

%Medium
randint (n3, 10, 20)
randint (n4, 15, 25)
%Medium

%Hard
randint (n5, 20, 40)
randint (n6, 25, 45)
%Hard

Text.LocateXY (200, 600)
put "

-----------------------------------
kznavy
Fri Feb 12, 2010 8:27 pm

RE:Math quiz program
-----------------------------------
 
setscreen ("graphics:600;600") 
var nq, n1, n2, n3, n4, n5, n6, x, y, o, user, ccounter, wcounter,counter : int 
nq := 0 
ccounter := 0 
wcounter := 0 
counter := 0 

var dif, correct, wrong : string 
correct := "*CORRECT*" 
wrong := "-WRONG-" 


%Easy 
randint (n1, 1, 5) 
randint (n2, 5, 10) 
%Easy 

%Medium 
randint (n3, 10, 20) 
randint (n4, 15, 25) 
%Medium 

%Hard 
randint (n5, 20, 40) 
randint (n6, 25, 45) 
%Hard 

Text.LocateXY (200, 600) 
put "

-----------------------------------
ProgrammingFun
Fri Feb 12, 2010 8:54 pm

RE:Math quiz program
-----------------------------------
mods could you please add syntax tags to this
thanks :D

There is a crazy glitch in your program in hard multiplication
You should check it out

Next time you program, comment more to help yourself and those helping you.
This program is very inefficient and glitchy.

You should improve on this and maybe add GUI

-----------------------------------
kznavy
Sat Feb 13, 2010 8:47 pm

RE:Math quiz program
-----------------------------------
Sorry guys, i am very new to ruing (-1 week)
I need some guidlines @.@

-----------------------------------
SNIPERDUDE
Sat Feb 13, 2010 9:04 pm

RE:Math quiz program
-----------------------------------
May I present, The Turing Walkthrough.

-----------------------------------
Turing_Gamer
Sun Feb 14, 2010 5:06 pm

Re: Math quiz program
-----------------------------------
Why not go to my computer engineering teacher's web site and do the tutorials. [url=http://mr-d.ca/]Click me

The tutorials include:
 - Turing
 - Java
 - Python
 - MIPS
 - Electronics

Tasks included

-----------------------------------
Prince Pwn
Sun Feb 14, 2010 6:38 pm

Re: Math quiz program
-----------------------------------
Before you post your code, in Turing press F2 to auto-indent. Also, check out other posts on the forums for tutorials and view source code in the submissions section and study how they work. Also, check out the above teachers website and you can also check out my old teachers site: [url=http://mrkurz.ca/]www.mrkurz.ca. Google Chrome points out a warning and I e-mailed him about it but his site is safe.
