Quiz shows have been around since the early days of broadcasting. Some, like this one, are based on random chance.
The rules of this Quiz Show are as follows. Two numbers are chosen randomly, between one and ten. A math operator is also randomly chosen (+, -, *, \ (integer division), or Mod). The contestant is shown the question, and then asked for the answer. Each incorrect guess makes the contestant lose one point, and each correct answer is scored based on the type of question it is:
| + | 2 points |
| - | 3 points |
| * | 4 points |
| \ | 5 points |
| Mod | 6 points |
After ten questions, the game ends and the final score is displayed.
Create an application that runs this Quiz Show for one contestant. Use a InputBox to get the answer from the user. Keep asking the user for the answer to a question until he or she gets it right. Keep a running total of the user's score, starting at zero, and report the score at the end of the game.
HINTS: Use either a Do-Loop-While or a Do-While-Loop (you'll have to figure out which) to run the answer algorithm until the user gets it right. You'll need a variable for the score. You'll also have to figure out a good algorithm for selecting a random operator. This isn't an obvious lab, so try using decomposition first!
Here's the code I used:
'Aaron Pavao
'07 November 2019
'Quiz Show
'A quiz show game for one player
'I'm Commander Shepard and this is my favorite program in the Citadel.
Public Class frmQuizShow
Private Sub frmQuizShow_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Randomize()
End Sub
Private Sub btnPlay_Click(sender As Object, e As EventArgs) Handles btnPlay.Click
Dim intA As Integer, intB As Integer, intOp As Integer, intAnswer As Integer
Dim intScore As Integer, booDone As Boolean, intQuestion As Integer, intResponse As Integer
intScore = 0
For intQuestion = 1 To 10
booDone = False
intA = Int(Rnd() * 10) + 1
intB = Int(Rnd() * 10) + 1
intOp = Int(Rnd() * 5) + 2
lblA.Text = intA
lblB.Text = intB
If intOp = 2 Then
lblOp.Text = "+"
intAnswer = intA + intB
ElseIf intOp = 3 Then
lblOp.Text = "-"
intAnswer = intA - intB
ElseIf intOp = 4 Then
lblOp.Text = "*"
intAnswer = intA * intB
ElseIf intOp = 5 Then
lblOp.Text = "\"
intAnswer = intA \ intB
Else
lblOp.Text = "Mod"
intAnswer = intA Mod intB
End If
Do
intResponse = InputBox("What is the answer?", "Question " & intQuestion)
If intResponse = intAnswer Then
MsgBox("That's right!",, "Correct")
intScore += intOp
lblScore.Text = intScore
booDone = True
Else
MsgBox("That's wrong!",, "Incorrect")
intScore -= 1
lblScore.Text = intScore
End If
Loop While Not booDone
Next
MsgBox("Final Score: " & intScore,, "Game Over")
End Sub
End Class