
-----------------------------------
kristinnugent
Tue Jan 15, 2013 1:42 pm

Trivia Game Glitch Related to Variables
-----------------------------------
I am trying to code a simple trivia game, but I'm having some trouble. I have the user input a character to choose what letter in the multiple choice they want to answer with, but only the first answer registers. After that, it tells the user every answer they enter is wrong, even if it should be right. Here is my code:






I think I am using Turing 4.1.1. Any idea/help on why it's not working would be greatly appreciated. If you need anymore information from me, just ask.

-----------------------------------
Insectoid
Tue Jan 15, 2013 6:11 pm

RE:Trivia Game Glitch Related to Variables
-----------------------------------
You might want to indent your code. It's not the problem, but I can't read it like this.

%Only put this once at the beginning of the program---------------- 
var score, correct: int 
var endgame: string 
var answer, answer2: char 
score:= 0 
correct:= 0 

%------------------------------------------------------------------ 
var MeanGirlsTrivia: int 
MeanGirlsTrivia:= Window.Open ("position:200;200,graphics:650;470") 
colourback(62) 
cls 
%Remove this and above section when adding to final program-------- 
var titlefont, subtitlefont, normalfont: int 
titlefont := Font.New ("Broadway:40") 
subtitlefont :=Font.New ("Harrington:20:bold") 
normalfont :=Font.New ("Calibri:12") 

%------------------------------------------------------------------ 
colourback (62) 
cls 

Font.Draw ("Who are Cady's first friends at North Shore High?", 165, 375, subtitlefont, magenta) 

Font.Draw ("A. Kevin Gnapoor & Damien", 20, 250, normalfont, magenta) 
Font.Draw ("B. Regina George & Gretchen Wieners",20, 200, normalfont, magenta) 
Font.Draw ("C. Janis Ian & Damien", 20, 150, normalfont, magenta) 
Font.Draw ("D. Kevin Gnapoor & Regina George", 20, 100, normalfont, magenta) 
Font.Draw ("Answer: ", 20, 57, normalfont, magenta) 

Text.Locate (26, 11) 
Text.Colour (magenta) 

get answer 

if answer="c"  then 
    score:=score+4 
    correct:= correct+1 
    cls 
    colourback (62) 
    cls 
    Font.Draw ("Correct!", 190, 250, titlefont,  magenta) 
    Font.Draw ("Press Enter to Continue...", 220, 200, normalfont, magenta) 
else if answer="e" then 
    var MeanGirlsExit: int 
    MeanGirlsExit:= Window.Open ("position:200;200,graphics:650;470") 
    colourback(62) 
    cls 

    Font.Draw ("Are you sure?", 120, 260, titlefont, magenta) 
    Font.Draw ("Type 'yes' to quit.", 50, 200, subtitlefont, magenta) 
    Font.Draw ("Type 'no' to return to the game.", 50, 180, subtitlefont, magenta) 
    Text.Locate (23, 20) 
    Text.Colour(magenta) 
    get endgame 

    if endgame="yes" then 
        Window.Close(MeanGirlsExit) 
        Window.Close(MeanGirlsTrivia) 
    else 
        Window.Close(MeanGirlsExit) 
    end if 

else 
    cls 
    colourback (62) 
    cls 
    Font.Draw ("Wrong!", 190, 250, titlefont, magenta) 
    Font.Draw ("Press Enter to Continue...", 220, 200, normalfont, magenta) 
end if 

end if 

Input.Pause 
cls 

%--------------------------------------Question 2-------------------------------- 
colourback (62) 
cls 

Font.Draw ("Who are Cady's second friends at North Shore High?", 165, 375, subtitlefont, magenta) 

Font.Draw ("A. Kevin Gnapoor & Damien", 20, 250, normalfont, magenta) 
Font.Draw ("B. Regina George & Gretchen Wieners",20, 200, normalfont, magenta) 
Font.Draw ("C. Janis Ian & Damien", 20, 150, normalfont, magenta) 
Font.Draw ("D. Kevin Gnapoor & Regina George", 20, 100, normalfont, magenta) 
Font.Draw ("Answer: ", 20, 57, normalfont, magenta) 

Text.Locate (26, 11) 
Text.Colour (magenta) 

get answer2 

if answer2="b"  then 
    score:=score+4 
    correct:= correct+1 
    cls 
    colourback (62) 
    cls 
    Font.Draw ("Correct!", 190, 250, titlefont, magenta) 
    Font.Draw ("Press Enter to Continue...", 220, 200, normalfont, magenta) 
else if answer2="e" then 
    var MeanGirlsExit: int 
    MeanGirlsExit:= Window.Open ("position:200;200,graphics:650;470") 
    colourback(62) 
    cls 

    Font.Draw ("Are you sure?", 120, 260, titlefont, magenta) 
    Font.Draw ("Type 'yes' to quit.", 50, 200, subtitlefont, magenta) 
    Font.Draw ("Type 'no' to return to the game.", 50, 180, subtitlefont, magenta) 
    Text.Locate (23, 20) 
    Text.Colour(magenta) 
    get endgame 

    if endgame="yes" then 
        Window.Close(MeanGirlsExit) 
        Window.Close(MeanGirlsTrivia) 
    else 
       Window.Close(MeanGirlsExit) 
    end if 

else 
    cls 
    colourback (62) 
    cls 
    Font.Draw ("Wrong!", 190, 250, titlefont, magenta) 
    Font.Draw ("Press Enter to Continue...", 220, 200, normalfont, magenta) 
end if 

end if 

Input.Pause 
cls 

Looks to me like this code shouldn't even compile. You've got two extra 'end if's that don't need to be there.

-----------------------------------
kristinnugent
Wed Jan 16, 2013 1:23 pm

RE:Trivia Game Glitch Related to Variables
-----------------------------------
When I first programmed the code, I didn't have the last end if, but Turing wouldn't let me run the program without it, because it said it was missing, though I could not figure out from where.

-----------------------------------
kristinnugent
Wed Jan 16, 2013 1:29 pm

RE:Trivia Game Glitch Related to Variables
-----------------------------------
It specifically says "Syntax error at 'End of File', expected 'end if'

-----------------------------------
Dreadnought
Wed Jan 16, 2013 2:47 pm

Re: Trivia Game Glitch Related to Variables
-----------------------------------
I think the confusion is that in Turing "else if" is "elsif".
