/* Write a program that asks the user the same single,
simple, random math problem until they get it right
(a) allow the user to specify the number of problems */
var firstDigit, secondDigit : int
var answer, correctAnswer : int
var numProblems : int
var continue : string
numProblems := 0 % user has answered no problems
continue := "yes" % assume the user wants to continue
loop
randint (firstDigit, 1, 9)
randint (secondDigit, 1, 9)
correctAnswer := firstDigit + secondDigit
answer := -99 %initialize to a value that cannot be right
loop
put "What is ", firstDigit, " + ", secondDigit, " = " ..
get answer
if (answer = correctAnswer) then
put "That is correct"
else
put "Sorry, try again..."
end if
exit when (answer = correctAnswer)
end loop
numProblems := numProblems + 1
put "Do you wish to continue? " ..
get continue
exit when (continue = "no") or (continue = "No") or (continue = "NO")
end loop
put "You answered ", numProblems, " problems"
Comments (0)
You don't have permission to comment on this page.