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

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




PostPosted: Wed Apr 28, 2004 9:05 pm   Post subject: Help with quiz

Hi I just need to know how to keep score without doing the if statement every time to do " 1 out of 3 " etc thanx

code:

setscreen ("graphics:max;max,nobuttonbar")

colorback (red)
put "Welcome to my quiz" ..
cls       
var name : string
var guess : int
var guess2 : int
var guess3 : int
var guess4 : int
var guess5 : int
var guess6 : int
var guess7 : int
var guess8 : int
var guess9 : int
var guess10 : int
var guessbonus : int

put "Welcome to my quiz!!!!!!"
delay (2000)
put "I have programmed a guide to help you through the quiz, his name is Sam"
delay (1500)
put "Sam: This quiz will affect your final mark!"
delay (2000)
put "Enter your name"
get name

put "Sam will now find more information about you"
delay (6000)
% The "ShowUserName" program.
var userName := Sys.GetUserName
if Error.Last not= 0 then
    put "Sys.GetUserName failed: ", Error.LastMsg
else
    put "User Name: ", userName
end if

var computerName := Sys.GetComputerName
if Error.Last not= 0 then
    put "Sys.GetComputerName failed: ", Error.LastMsg
else
    put "Computer Name: ", computerName
end if


put "Sam: Now for your first question"
delay (1500)
put "25+30"
delay (1200)

put "Sam: Enter your guess, Now"
get guess
if guess = 55 then
    put "Your correct"
else
    put "haha you can't add"
end if
delay (2000)
if guess = 55 then
    put "1 out of 1"
else
    put "0 out of 1"
end if

delay (1500)

cls

put "Sam: Second question "
delay (1500)
put "22 div 2"
put "Sam: Enter your guess, Now"
get guess2
if guess2 = 11 then
    put "Your correct"
else
    put "WRONG! "
end if


if guess = 55 and guess2 = 11 then
    put "2 out of 2"
end if

if guess not= 55 and guess2 = 11 then
    put "1 out of 2"
end if

if guess = 55 and guess2 not= 11 then
    put "1 out of 2"
end if

if guess not= 55 and guess2 not= 11 then
    put "Your not doing well, 0 out of 2"
end if

put "Sam: Third Question"
delay (1500)
put "12*12"
put "Sam: Enter your guess, Now"
get guess3
if guess3 = 144 then
    put "Your correct"
else
    put "WRONG!"
end if

if guess = 55 and guess2 = 11 and guess3 = 144 then
    put "3 out of 3"
end if

if guess not= 55 and guess2 = 11 and guess3 = 144 then
    put "2 out of 3"
end if

if guess = 55 and guess2 not= 11 and guess3 = 144 then
    put "2 out of 3"
end if

if guess = 55 and guess2 = 11 and guess3 not= 144 then
    put "2 out of 3"
end if

if guess not= 55 and guess2 not= 11 and guess3 = 144 then
    put "1 out of 3"
end if
if guess = 55 and guess2 not= 11 and guess3 not= 144 then
    put "1 out of 3"
end if
if guess not= 55 and guess2 = 11 and guess3 not= 144 then
    put "1 out of 3"
end if
if guess not= 55 and guess3 not= 11 and guess3 not= 144 then
    put "NOT DOING GOOD!!!! 0 out of 3"
end if

Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Wed Apr 28, 2004 9:09 pm   Post subject: (No subject)

there is alot easer way of doing this, if u just store each question in an array and the right awaer in another one then u could ask all the questions in a loop with one if stament and one get and one put.

any how since u are all ready checking if the awaser is right after the question why not just make a var like score with is an int and and 1 to it each time they get a question right and you print out corcect?

then at the end just output "you got ", score, " out of 3"
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
doey55




PostPosted: Wed Apr 28, 2004 9:10 pm   Post subject: (No subject)

could you give me an example plz
Dan




PostPosted: Thu Apr 29, 2004 1:52 pm   Post subject: (No subject)

this is an example of adding a var to count the right questions.

code:

setscreen ("graphics:max;max,nobuttonbar")

colorback (red)
put "Welcome to my quiz" ..
cls       
var name : string
var guess : int
var guess2 : int
var guess3 : int
var guess4 : int
var guess5 : int
var guess6 : int
var guess7 : int
var guess8 : int
var guess9 : int
var guess10 : int
var guessbonus : int

var sorce:int := 0

put "Welcome to my quiz!!!!!!"
delay (2000)
put "I have programmed a guide to help you through the quiz, his name is Sam"
delay (1500)
put "Sam: This quiz will affect your final mark!"
delay (2000)
put "Enter your name"
get name

put "Sam will now find more information about you"
delay (6000)
% The "ShowUserName" program.
var userName := Sys.GetUserName
if Error.Last not= 0 then
    put "Sys.GetUserName failed: ", Error.LastMsg
else
    put "User Name: ", userName
end if

var computerName := Sys.GetComputerName
if Error.Last not= 0 then
    put "Sys.GetComputerName failed: ", Error.LastMsg
else
    put "Computer Name: ", computerName
end if


put "Sam: Now for your first question"
delay (1500)
put "25+30"
delay (1200)

put "Sam: Enter your guess, Now"
get guess
if guess = 55 then
    put "Your correct"
    sorce+=1
else
    put "haha you can't add"
end if
delay (2000)

put sorce, " out of 1"


delay (1500)

cls

put "Sam: Second question "
delay (1500)
put "22 div 2"
put "Sam: Enter your guess, Now"
get guess2
if guess2 = 11 then
    put "Your correct"
    sorce+=1
else
    put "WRONG! "
end if


put sorce, " out of 2"


put "Sam: Third Question"
delay (1500)
put "12*12"
put "Sam: Enter your guess, Now"
get guess3
if guess3 = 144 then
    put "Your correct"
    sorce += 1
else
    put "WRONG!"
end if

put sorce, " out of 3"
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
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  [ 4 Posts ]
Jump to:   


Style:  
Search: