GrandMicky's quiz syntax errors
Author |
Message |
GrandMicky
|
Posted: Sat May 22, 2010 8:40 am Post subject: RE:[tutorial] loops and faking goto line |
|
|
I need help with my code
turing always tells me there is a syntax error at 'end of file' expected 'end if' but when i change it the same thing shows up , except for 'end loop'
var answer1:string
var answer2:int
var answer3:string
var answer4:string
var answer5:real
var response:string
var response2:string
put "Hello! What is your name?"
get answer1:*
put "Hello,", answer1," how old are you?"
get answer2
put "So you are ",answer2," years old"
put "that is interesting"
put "what is your favorite hobby?"
get answer3
put "I like to do that too!"
put "I have my ways."
put "Are you good at math?"
get answer4
if answer4 = "yes" then
loop
put "what is 2+3"
get answer5
if answer5 not= 5 then
put "try again"
elsif answer5 = 5 then
put "correct"
end if
end loop
put "Wow you are smart."
put "What do you want to become when you are older?"
get response
put "That is very interesting."
put "Well i have to go now, goodbye"
get response2 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Sat May 22, 2010 1:28 pm Post subject: RE:GrandMicky\'s quiz syntax errors |
|
|
If you indent your code, you will see where your control structures (ifs, loops) don't line up (that is, where an "end" is missing). |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Monduman11
|
Posted: Sat May 22, 2010 7:26 pm Post subject: Re: GrandMicky's quiz syntax errors |
|
|
you could also just press ctrl enter and it should auto close loops, if statements, and fors. try it out and u will see that it fixes ur program.
you should also add an exit when answer5 = 5
code: |
if answer5 not= 5 then
put "try again"
elsif answer5 = 5 then
put "correct"
exit when answer5= 5 |
so that if the anwer is 5 it exits the loop or else it just keeps on looping |
|
|
|
|
|
|
|