Posted: Thu Feb 11, 2010 8:45 pm Post subject: 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-"
Text.LocateXY (200,600)
put "[WELCOME TO MATH PRACTICE] V.1"
loop
Text.LocateXY (0,550)
put "How many questions would you like?"
get nq
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
Text.LocateXY (0,500)
put "What operation would you like to practice? (add = 1,sub = 0)"
get o
if o = 1 then
o := add
s := +
end if
if o = 0 then
o := sub
s := -
end if
put "let's begin"
put y,s,x
get user
if user = y,s,x then
put correct
else
put wrong
end if
exit when nq = nq
end loop
[/syntax]
Please specify what version of Turing you are using
4.1.1
Sponsor Sponsor
Zren
Posted: Thu Feb 11, 2010 9:26 pm Post subject: 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
Posted: Thu Feb 11, 2010 9:36 pm Post subject: RE:Math quiz program
how do i ident D:
Zren
Posted: Thu Feb 11, 2010 9:48 pm Post subject: Re: Math quiz program
F2 or click the big grey button---v
[Run] [Pause] [Open] [Save] [Indent]
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 operator or range ie. (-infinity, 0) or (0, inifinity) aka Negative or Postive.
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
Posted: Thu Feb 11, 2010 10:03 pm Post subject: Re: Math quiz program
If you want, you can have random equations like so...
Turing:
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 =1then
symbol := +
else
symbol := -
endif put Num1 + " " + symbol + " " + Num2 + " =" get reply
%Boolean logic determining if operation match reply then correct, else incorrect %Reset code endfor
This isn't a correct way to do it, just a hint of what to do.
kznavy
Posted: Thu Feb 11, 2010 10:11 pm Post subject: RE:Math quiz program
Can i get THE correct way to do it, i am confused =_=
Zren
Posted: Thu Feb 11, 2010 10:15 pm Post subject: RE:Math quiz program
Did you find the missing end __ statement? And if so, post your updated code.
kznavy
Posted: Fri Feb 12, 2010 6:43 pm Post subject: 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
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
____________________
Sponsor Sponsor
TerranceN
Posted: Fri Feb 12, 2010 7:03 pm Post subject: 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
Posted: Fri Feb 12, 2010 7:44 pm Post subject: RE:Math quiz program
For future reference, syntax highlighting for code makes it easy to read.
code:
[syntax="Turing"] % code here . . . [/syntax]
kznavy
Posted: Fri Feb 12, 2010 7:51 pm Post subject: RE:Math quiz program
Turing:
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-"
put"What difficulty would you like? (easy,medium,hard)" get dif
if dif ="easy"then
x := n1
y := n2
endif if dif ="medium"then
x := n3
y := n4
endif if dif ="hard"then
x := n5
y := n6
endif
Text.LocateXY(0, 500) put"What operation would you like to practice? (add = 1,sub = 0,multi = 2)" get o
if o =1then 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 exitwhen counter = nq
endif endif
if o =0then 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
exitwhen counter = nq
endif endif
Text.LocateXY(300, 300) put"NUMBER OF QUESTIONS RIGHT" put ccounter
Text.LocateXY(300, 250) put"NUMBER OF QUESTIONS WRONG" put wcounter
end loo
SNIPERDUDE
Posted: Fri Feb 12, 2010 8:06 pm Post subject: 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 [typically]). This way, it is easy to determine whether we are closing blocks properly or not.
Turing:
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-"
put"What difficulty would you like? (easy,medium,hard)" get dif
if dif ="easy"then
x := n1
y := n2
endif if dif ="medium"then
x := n3
y := n4
endif if dif ="hard"then
x := n5
y := n6
endif
Text.LocateXY(0, 500) put"What operation would you like to practice? (add = 1,sub = 0,multi = 2)" get o
if o =1then 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 exitwhen counter = nq
endif endif
if o =0then 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
exitwhen counter = nq
endif endif
Text.LocateXY(300, 300) put"NUMBER OF QUESTIONS RIGHT" put ccounter
Text.LocateXY(300, 250) put"NUMBER OF QUESTIONS WRONG" put wcounter
endloop
ProgrammingFun
Posted: Fri Feb 12, 2010 8:54 pm Post subject: RE:Math quiz program
mods could you please add syntax tags to this
thanks
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
Posted: Sat Feb 13, 2010 8:47 pm Post subject: RE:Math quiz program
Sorry guys, i am very new to ruing (-1 week)
I need some guidlines @.@