Question

Integer Math- Console based---uses Windows Form in Visual Basic   Create an application that uses random integers...

Integer Math- Console based---uses Windows Form in Visual Basic  

Create an application that uses random integers to test the user’s knowledge of arithmetic. Let the user choose from addition, subtraction, multiplication, and division. The integers used in the problems should range from 20 to 120. When giving feedback, use color to differentiate between a correct answer response, versus an incorrect answer response. Also check for non-integer input. Preparing division problems requires special consideration because the quotient must be an integer. Therefore, you can use a loop to generate new random values for the second operand until you find one that divides the first operand evenly. Use the Mod operator to verify that the integer division remainder is zero.

For Visual Basic!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

Public Class Form1
Dim r As Random = New Random
Dim no1, no2 As Integer
Private Sub rdbAdd_CheckedChanged(sender As Object, e As EventArgs) Handles rdbAdd.CheckedChanged
txtAnswer.Clear()
txtAnswer.BackColor = Color.White
no1 = randomInt()
no2 = randomInt()
lblOperation.Text = "+"
txtNumber1.Text = no1.ToString()
txtNumber2.Text = no2.ToString()
End Sub
Public Function randomInt() As Integer
Return r.Next(20, 120)
End Function

Private Sub rdbSub_CheckedChanged(sender As Object, e As EventArgs) Handles rdbSub.CheckedChanged
txtAnswer.Clear()
txtAnswer.BackColor = Color.White
no1 = randomInt()
no2 = randomInt()
lblOperation.Text = "-"
txtNumber1.Text = no1.ToString()
txtNumber2.Text = no2.ToString()
End Sub

Private Sub rdbMul_CheckedChanged(sender As Object, e As EventArgs) Handles rdbMul.CheckedChanged
txtAnswer.Clear()
txtAnswer.BackColor = Color.White
no1 = randomInt()
no2 = randomInt()
lblOperation.Text = "*"
txtNumber1.Text = no1.ToString()
txtNumber2.Text = no2.ToString()
End Sub

Private Sub rdbDiv_CheckedChanged(sender As Object, e As EventArgs) Handles rdbDiv.CheckedChanged
txtAnswer.Clear()
txtAnswer.BackColor = Color.White
no1 = randomInt()
lblOperation.Text = "/"
txtNumber1.Text = no1.ToString()
Do
no2 = randomInt()
If no1 Mod no2 = 0 Then
Exit Do
End If
Loop
txtNumber2.Text = no2.ToString()

End Sub

Private Sub btnCheckAns_Click(sender As Object, e As EventArgs) Handles btnCheckAns.Click
Dim userAnswer = txtAnswer.Text

Try
Integer.TryParse(txtAnswer.Text, userAnswer)
If rdbAdd.Checked = True Then
If Val(txtAnswer.Text) = no1 + no2 Then
txtAnswer.BackColor = Color.Green
Else
txtAnswer.BackColor = Color.Red
End If
End If
If rdbSub.Checked = True Then
If Val(txtAnswer.Text) = no1 - no2 Then
txtAnswer.BackColor = Color.Green
Else
txtAnswer.BackColor = Color.Red
End If
End If
If rdbMul.Checked = True Then
If Val(txtAnswer.Text) = no1 * no2 Then
txtAnswer.BackColor = Color.Green
Else
txtAnswer.BackColor = Color.Red
End If
End If
If rdbDiv.Checked = True Then
If Val(txtAnswer.Text) = no1 / no2 Then
txtAnswer.BackColor = Color.Green
Else
txtAnswer.BackColor = Color.Red
End If
End If
Catch ex As Exception
MsgBox("Please enter Intger")
End Try
End Sub
End Class

Design

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Integer Math- Console based---uses Windows Form in Visual Basic   Create an application that uses random integers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Visual Basic: Create an application that simulates a tic tac toe game. The form uses 9...

    Visual Basic: Create an application that simulates a tic tac toe game. The form uses 9 large labels to display the x's and o's. The application should use a two dimensional integer array to simulate the game board in memory. When the user clicks the "New Game" button the application should step throguh the array storing a random number of 0 to 1 in each element. The numer 0 represent the letter o and the number 1 reprsents the letter...

  • Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:

    Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:AdditionSubtractionMultiplicationDivisionModuloExponentThe following source files are already complete and CANNOT be changed:MathQuiz.java (contains the main() method)OperationType.java (defines an enumeration for valid math operations and related functionality)The following source files are incomplete and need to be coded to meet the indicated requirements:MathQuestionable.javaA Random object called RANDOM has already been declared and assigned, and you must not change this assignment in any way.Declare and assign an interface integer called MAX_SMALL and assign it the...

  • Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:

    Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:AdditionSubtractionMultiplicationDivisionModuloExponentThe following source files are already complete and CANNOT be changed:MathQuiz.java (contains the main() method)OperationType.java (defines an enumeration for valid math operations and related functionality)The following source files are incomplete and need to be coded to meet the indicated requirements:MathQuestionable.javaA Random object called RANDOM has already been declared and assigned, and you must not change this assignment in any way.Declare and assign an interface integer called MAX_SMALL and assign it the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT