0% found this document useful (0 votes)
48 views2 pages

Exercise 10

The document describes a math quiz program with the following functionality: 1) It generates random math problems by selecting two random numbers between 1-10 and a random operator (+, -, *, /). 2) It allows the user to enter an answer and checks if it is correct, displaying the appropriate message. 3) It has a button to reveal the correct answer if the user wants to see it. 4) It clears the answer field and messages when a new problem is generated.

Uploaded by

api-307933689
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views2 pages

Exercise 10

The document describes a math quiz program with the following functionality: 1) It generates random math problems by selecting two random numbers between 1-10 and a random operator (+, -, *, /). 2) It allows the user to enter an answer and checks if it is correct, displaying the appropriate message. 3) It has a button to reveal the correct answer if the user wants to see it. 4) It clears the answer field and messages when a new problem is generated.

Uploaded by

api-307933689
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Exercise 10

Public Class Form1


Private Sub btnNewProblem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNewProblem.Click
Dim operator1 As Integer
Randomize()
operator1 = Int(4 * Rnd() + 1)
Me.lblNum1.Text = Int(10 * Rnd() + 1)
Me.lblNum2.Text = Int(10 * Rnd() + 1)
Select Case operator1
Case 1
Me.lblOperator.Text
Case 2
Me.lblOperator.Text
Case 3
Me.lblOperator.Text
Case 4
Me.lblOperator.Text
End Select

= "+"
= "-"
= "*"
= "/"

Me.lblMessage.Text = Nothing
Me.txtAnswer.Clear()
End Sub
Private Sub btnCheckAnswer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCheckAnswer.Click
Dim num1 As Integer = Integer.Parse(Me.lblNum1.Text)
Dim num2 As Integer = Integer.Parse(Me.lblNum2.Text)
Dim operator1 As Char = Char.Parse(Me.lblOperator.Text)
Dim answer As Integer
Select Case operator1
Case "+"
answer = num1 + num2
Case "-"
answer = num1 - num2
Case "*"
answer = num1 * num2
Case "/"
answer = num1 / num2
End Select
If Val(Me.txtAnswer.Text) = answer Then
Me.lblMessage.Text = "You are correct!"
Else
Me.lblMessage.Text = "Wrong answer."
End If
End Sub
Private Sub btnShowAnswer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShowAnswer.Click
Dim operator1 As Char = Char.Parse(Me.lblOperator.Text)
Dim num1 As Integer = Integer.Parse(Me.lblNum1.Text)
Dim num2 As Integer = Integer.Parse(Me.lblNum2.Text)

Select Case operator1


Case "+"
Me.txtAnswer.Text
Case "-"
Me.txtAnswer.Text
Case "*"
Me.txtAnswer.Text
Case "/"
Me.txtAnswer.Text
End Select
End Sub

= num1 + num2
= num1 - num2
= num1 * num2
= num1 / num2

Private Sub txtAnswer_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txtAnswer.TextChanged
Me.lblMessage.Text = Nothing
End Sub
End Class

You might also like