Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 right answer
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nin




PostPosted: Tue Jan 16, 2007 7:41 pm   Post subject: right answer

how do u keep track of the user's right answers ( score), if you were doing a trivia game like mine?

Also how do you get the user's answer if they are able to type in anything they want?
and i want the answers to be in words not numbers the first 5 questions r suppose to b multiple choice and its ok like that.

code below:

code:


%Set screen up
import GUI
setscreen ("graphics")

%Declaration Section
var mainWin := Window.Open ("graphic: 640;200")
var key : string (1)
var number, randomNum : int
var try : int := 3
var mainMenuBtn, playBtn, nextBtn, nextBtn2, nextBtn3, nextBtn4, nextBtn5, nextBtn6, nextBtn7,
    quitBtn : int := 0

var rightAnswer := 1

%Title
proc title
    locate (1, 36)
    put "Math Game"
end title

%Introduction
proc introduction
    GUI.Refresh
    title
    locate (3, 1)
    put "This program will be testing your math skills."
    GUI.Show (mainMenuBtn)
    GUI.Hide (nextBtn)
    GUI.Hide (nextBtn2)
    GUI.Hide (nextBtn3)
    GUI.Hide (nextBtn4)
    GUI.Hide (nextBtn5)
    GUI.Hide (nextBtn6)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)
end introduction

%Main Menu
proc mainMenu
    cls
    GUI.Hide (mainMenuBtn)
    GUI.Hide (nextBtn)
    GUI.Show (playBtn)
    GUI.Show (quitBtn)
    title
    locate (3, 1)
    put "To proceed, please press any of the below buttons."
    GUI.Refresh
end mainMenu

%Random Number
proc randNum
    randint (randomNum, 10, 65)
end randNum

%Questions 1-5 error message
proc errorMessage
    var windID1 := Window.Open ("position:300;300,graphics: 330;100")
    locate (1, 1)
    put "Please enter 1, 2, 3 or 4."
    locate (5, 1)
    put "To proceed, please press any key" ..
    loop
        exit when hasch
    end loop
    Window.Close (windID1)
end errorMessage

%Question 1
proc question1
    cls
    title
    locate (3, 1)
    put "How do you calculate the volume of a prism? "
    locate (5, 1)
    put "1.V = Area of base x height"
    put "2.V = 1/3 x area of base x height" %right answer
    put "3.V = Base x 1/3 x base x height"
    put "4.V = Base x Height"
    locate (10, 1)
    put "Answer: " ..
    get number
    GUI.Show (nextBtn)
    GUI.Hide (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)

    if number < 1 or number > 5 then
        errorMessage
        question1
    end if
    GUI.Refresh
end question1

%Question2
proc question2
    cls
    title
    locate (3, 1)
    put "What is 70 percent of 70?"
    locate (5, 1)
    put "1. 70"
    put "2. 49" %right answer
    put "3. 40"
    put "4. 100"
    locate (10, 1)
    put "Answer: " ..
    get number
    GUI.Show (nextBtn2)
    GUI.Hide (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)

    if number < 1 or number > 5 then
        errorMessage
        question2
    end if
    GUI.Refresh

end question2

%Question3
proc question3
    cls
    title
    locate (3, 1)
    put "How many degress in a straight angle?"
    locate (5, 1)
    put "1. 20 degrees"
    put "2. 360 degrees"
    put "3. 180 degrees" %right answer
    put "4. 160 degrees"
    locate (10, 1)
    put "Answer: " ..
    get number
    GUI.Show (nextBtn3)
    GUI.Hide (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)

    if number < 1 or number > 5 then
        errorMessage
        question3

    end if
    GUI.Refresh

end question3

%Question4
proc question4
    cls
    title
    locate (3, 1)
    put "What is a decagon?"
    locate (5, 1)
    put "1. A 12 sided figure"
    put "2. A 16 sided figure"
    put "3. A 8 sided figure"
    put "4. A 10 sided figure" %right answer
    locate (10, 1)
    put "Answer: " ..
    get number
    GUI.Show (nextBtn4)
    GUI.Hide (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)

    if number < 1 or number > 5 then
        errorMessage
        question4
    end if
    GUI.Refresh

end question4

%Question 5
proc question5
    cls
    title
    locate (3, 1)
    put "What is a natural number?"
    locate (5, 1)
    put "1. whole numbers"
    put "2. negative numbers"
    put "3. one" %right answer
    put "4. any number"
    locate (10, 1)
    put "Answer: " ..
    get number
    GUI.Show (nextBtn5)
    GUI.Hide (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)

    if number < 1 or number > 5 then
        errorMessage
        question5
    end if
    GUI.Refresh

end question5

%Question 6
proc question6
    cls
    title
    locate (3, 1)
    put "How many kilometres are there in a megametre?"
    % answer : 1000
    locate (5, 1)
    put "Answer: "
    get number
    GUI.Show (nextBtn6)
    GUI.Hide (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)

end question6

%Question 7
proc question7
    cls
    title
    locate (3, 1)
    put "lala world"
    GUI.Show (nextBtn7)
    GUI.Show (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)
end question7

%Good Bye
proc goodBye
    var windID2 := Window.Open ("graphics:640;400")
    Window.Close (mainWin)
    locate (8, 32)
    put "Your Final score is: ", rightAnswer
    locate (10, 29)
    put "This program was written by:"
    locate (11, 35)
    put "Ninanori Agustin"
    locate (13, 38)
    put "Credits to:"
    locate (14, 26)
    put "http://www.quia.com/cb/22904.html"
    locate (15, 32)
    put "For the math questions"
    locate (17, 39)
    put "Goodbye!"
    delay (4000)
    Window.Close (windID2)
end goodBye

%Buttons
mainMenuBtn := GUI.CreateButtonFull (270, 160, 0, "Main Menu", mainMenu, 0, '^M', false)
playBtn := GUI.CreateButtonFull (282, 220, 0, "Start Game", question1, 0, '^P', false)
nextBtn := GUI.CreateButtonFull (400, 100, 0, "Next", question2, 0, '^N', false)
nextBtn2 := GUI.CreateButtonFull (500, 300, 0, "Next", question3, 0, '^2', false)
nextBtn3 := GUI.CreateButtonFull (100, 300, 0, "Next", question4, 0, '^3', false)
nextBtn4 := GUI.CreateButtonFull (400, 300, 0, "Next", question5, 0, '^4', false)
nextBtn5 := GUI.CreateButtonFull (200, 300, 0, "Next", question6, 0, '^5', false)
nextBtn6 := GUI.CreateButtonFull (150, 300, 0, "Next", question7, 0, '^6', false)
quitBtn := GUI.CreateButton (300, 100, 0, "Exit", GUI.Quit)

%Main Program
introduction
loop
    exit when GUI.ProcessEvent
end loop
goodBye

%End of program
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Jan 16, 2007 8:25 pm   Post subject: RE:right answer

Keeping track of the user's score is easy: just create an integer variable. Incriment it by one when they get an answer correct.

Getting the user's answer will require a bit of error checking, if you want to do it right. You've got all sorts of GUI in here, it seems, so I don't know how you want to do this. You could use a GUI textfield, or you could do it the simple way with put and get. In either case, you should probably have a loop asking for input and exiting only when proper input has been given.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: