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

Username:   Password: 
 RegisterRegister   
 How to keep score in a quiz on turing?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
CookieMonster




PostPosted: Sat Oct 19, 2013 11:42 am   Post subject: How to keep score in a quiz on turing?

Hi I'm super new to turing and for an assignment for school, I have to create a multiple choice quiz, and I need to keep score on how the user did. For example if the user gets the question right, it adds 10 points to the score. My codes so far is:

Turing:

%question 1
colour (blue)

var answer: string
var score : real
put "What is the answer to 92+5?"
put "a) 92"
put "b) 96"
put "c) 97"
put "d) 69"
put "e) 5"

put "Enter the letter that is the correct answer."
get answer

if answer = "a" then
put "Try again!"
elsif answer = "b" then
put "Incorrect!"
elsif answer = "c" then
put "You are right!"
elsif answer = "d" then
put "Wrong answer!"
elsif answer = "e" then
put "Your answer is wrong!"
else
put "That is an invalid answer please enter either a, b, c, d, or e."
end if

% Question 2
colour (blue)

var answer2: string

put "What is the answer to 9 x 8?"
put "a) 81"
put "b) 72"
put "c) 64"
put "d) 70"
put "e) 88"

put "Enter the letter that is the correct answer."
get answer2

if answer2 = "a" then
put "Try again!"
elsif answer2 = "b" then
put "You are right!"
elsif answer2 = "c" then
put "You are wrong!"
elsif answer2 = "d" then
put "Wrong answer!"
elsif answer2 = "e" then
put "Your answer is wrong!"
else
put "That is an invalid answer please enter either a, b, c, d, or e."
end if


I also need to incorporate a loop in to the assignment, how should i do that?



Mod Edit:
Please wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
code:

[syntax="turing"] ... code ... [/syntax]

[code] ... code ... [/code ]
Sponsor
Sponsor
Sponsor
sponsor
Nathan4102




PostPosted: Sat Oct 19, 2013 11:52 am   Post subject: RE:How to keep score in a quiz on turing?

Just below put"Correct", increment a score variable by your chosen amount. To add a loop, you could make an option to retake the quiz.
Raknarg




PostPosted: Sat Oct 19, 2013 11:58 am   Post subject: RE:How to keep score in a quiz on turing?

Turing:

if answerIsCorrect () then
   score := score + 10
   % or score += 1
end if
hgrad98




PostPosted: Mon Oct 28, 2013 8:00 pm   Post subject: RE:How to keep score in a quiz on turing?

[syntax="turing"]
var score : int
var score := 0

if answer = correct then
hgrad98




PostPosted: Mon Oct 28, 2013 8:04 pm   Post subject: RE:How to keep score in a quiz on turing?

var score : int
score := 0

if answer = "correct" then
put "You are correct!"
score := score + 1
end if

if answer = "wrong" then
put "You are incorrect!"
score := score + 0
end if

... and so on

put "your total is: ", score

you're welcome
hgrad98




PostPosted: Mon Oct 28, 2013 8:05 pm   Post subject: RE:How to keep score in a quiz on turing?

sorry about the double post my computer went stupid and replied it while i was typing
Zren




PostPosted: Mon Oct 28, 2013 8:45 pm   Post subject: RE:How to keep score in a quiz on turing?

You should be using an else statement for the section where you're "wrong". Otherwise you're implying there are 4 different states rather than just 2.
hgrad98




PostPosted: Tue Oct 29, 2013 4:43 pm   Post subject: RE:How to keep score in a quiz on turing?

it doesn't really matter though. it doesn't change it
Sponsor
Sponsor
Sponsor
sponsor
hgrad98




PostPosted: Tue Oct 29, 2013 4:49 pm   Post subject: RE:How to keep score in a quiz on turing?

and i meant

+ 10

not + 1
kim1590




PostPosted: Sat Nov 24, 2018 12:08 pm   Post subject: Re: How to keep score in a quiz on turing?

i also need help i have a similar code but when the user gets the wrong answer once they get a second chance but for some reason after their second chance when they get it right it repeats the question

MY CODE:


loop
%kim farni
%variables
var number1 : int
var number2 : int
var number3 : int
var number4 : int
var number5 : int
var number6 : int
var number7 : int
var number8 : int
var number9 : int
var score : int
score := 0
var numberoftries : int
numberoftries := 0
var guess : int

%setting ranges for variables
randint (number6, 10, 15)
randint (number7, 10, 15)
randint (number8, 10, 15)
randint (number9, 10, 15)

%prints the question on screen
put "your score is ", score
put "you have tried ", numberoftries.. put " times"
put "what is the answer to the following quetion?"
put number6 ..
put " x " ..
put number7

%setting ranges for variables
randint (number1, 1, 3)
randint (number2, 4, 5)
randint (number3, 6, 7)
randint (number4, 8, 9)
randint (number5, 10, 11)

%prints on screen choices
put " a) " ..
put number1
put " b) " ..
put number6 * number7
put " c) " ..
put number3
put " d) " ..
put number4
put " e) " ..
put number5

get guess %gives users a chance to put in their guess

%if the users puts the right answer then it says correct
if guess = number6 * number7 then
put "correct! the answer was ", number6 * number7
score := score + 1
numberoftries := numberoftries + 1
put "your score is ", score
put "you have tried ", numberoftries.. put " times"
end if

%if the user puts in a bigger number than the answer then it shows incorrect and puts another story
if guess > number6 * number7 then
score := score + 0
numberoftries := numberoftries +1
put "you have tried ", numberoftries.. put " times"
put "incorrect your score is now ", score
put "the answer was ", number6 * number7 ..
put " try again!"
put number8 ..
put " x " ..
put number9
put " a) " ..
put number4
put " b) " ..
put number8 * number9
put " c) " ..
put number1
put " d) " ..
put number3
put " e) " ..
put number5
get guess
elsif guess < number6 * number7 then
score := score + 0
numberoftries := numberoftries +1
put "you have tried ", numberoftries.. put " times"
put "incorrect your score is now ", score
put "the answer was ", number6 * number7 ..
put " try again!"
put number8 ..
put " x " ..
put number9
put " a) " ..
put number4
put " b) " ..
put number8 * number9
put " c) " ..
put number1
put " d) " ..
put number3
put " e) " ..
put number5
get guess
end if

exit when guess = number6 * number7
end loop

%put "your total is: ", score
Insectoid




PostPosted: Mon Nov 26, 2018 1:55 pm   Post subject: RE:How to keep score in a quiz on turing?

What happens if you give the wrong answer for the 1st question, then for the 2nd question give the correct answer for the 1st question? Ie

>What is 2x3?
4
>Wrong, what is 4x7?
6

What will the program do here? What is it supposed to do?
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  [ 11 Posts ]
Jump to:   


Style:  
Search: