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:
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 '12 April 2017 'Quiz Show 'A short quiz game that asks math questions. 'Our first child is due on Sunday! Public Class frmQuizShow Private Sub btnPlay_Click(sender As Object, e As EventArgs) Handles btnPlay.Click Dim intScore As Integer Dim intAnswer As Integer, intResponse As Integer Dim intOp As Integer Dim intNum1 As Integer, intNum2 As Integer Dim intQuestion As Integer intScore = 0 lblScore.Text = intScore For intQuestion = 1 To 10 intNum1 = Int(Rnd() * 10) + 1 intNum2 = Int(Rnd() * 10) + 1 intOp = Int(Rnd() * 5) + 2 lblNum1.Text = intNum1 lblNum2.Text = intNum2 If intOp = 2 Then lblOp.Text = "+" intAnswer = intNum1 + intNum2 ElseIf intOp = 3 Then lblOp.Text = "-" intAnswer = intNum1 - intNum2 ElseIf intOp = 4 Then lblOp.Text = "*" intAnswer = intNum1 * intNum2 ElseIf intOp = 5 Then lblOp.Text = "\" intAnswer = intNum1 \ intNum2 Else lblOp.Text = "Mod" intAnswer = intNum1 Mod intNum2 End If Do intResponse = InputBox("What is the answer?", "Question #" & intQuestion) If intResponse = intAnswer Then intScore += intOp 'intScore = intScore + intOp lblScore.Text = intScore MsgBox("Correct!", , "Correct") Else intScore -= 1 lblScore.Text = intScore MsgBox("Try again.", , "Incorrect") End If Loop While intResponse <> intAnswer Next intQuestion MsgBox("Your final score is " & intScore, , "Game Over") End Sub Private Sub frmQuizShow_Load(sender As Object, e As EventArgs) Handles MyBase.Load Randomize() End Sub End Class