I need to create an application that displays math problems by randomly generating two numbers, 1 through 10, and an operator (*, -, /, +) and prompts the user for an answer. The application should check the answer and display a message, display the correct answer and generate a new problem.(High school programing)
But Iam having problems on how to do the second operator. This is how did the first B,

]Dim rnd As New System.Random
    Private Sub btnProblem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProblem.Click
        'Purpose-  to Create an application math problems by randomly generating 2 numbers , 1-10 & operators (/*-+)& prompts the user for an answer
        'Input- the answer
        'output- the problem, a prompt telling the user whether he is right & the answer
        

        Dim t As Integer
        Dim y As Integer


        Dim answer As Integer
        Dim guess As Integer


        If Me.lbl2.Text = "+" Then

        End If


        y = rnd.Next(10)
        t = rnd.Next(10)
        Me.lblR.Text = y
        Me.lblt.Text = t
        Me.lbl2.Text = "+"
        guess = Me.txtanswer.Text
        answer = t + y

    Private Sub btnchecck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnchecck.Click
        Dim t As Integer
        Dim y As Integer


        Dim guess As Integer
        Dim answer As String
        y = rnd.Next(10)
        t = rnd.Next(10)
        Me.lblR.Text = y
        Me.lblt.Text = t
        Me.lbl2.Text = "+"
        guess = Me.txtanswer.Text
        answer = t + y
        If guess = answer Then
            Me.lblanswercheck.Text = " The answer is correct"
        Else
            Me.lblanswercheck.Text = " The answer is wrong"

    Private Sub btnAnswer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnswer.Click
        Dim t As Integer
        Dim y As Integer


        Dim guess As Integer
        Dim answer As String
        y = rnd.Next(10)
        t = rnd.Next(10)
        Me.lblR.Text = y
        Me.lblt.Text = t
        Me.lbl2.Text = "+"
        guess = Me.txtanswer.Text
        answer = t + y
        If guess = answer Then
            Me.lblanswercheck.Text = "the answer is coorect"
        Else
            Me.lblanswercheck.Text = " The  answer is " & answer

        End If
    End Sub
End Class

Recommended Answers

All 2 Replies

I don't understand at all what you wanna do. I don't understand the code either.
Anyway, I'll try to help.
First, I'm surprising that you haven't wrote no "end sub" instruction. Maybe there's some things that I don't know yet. The second thing is the first "If..." because it's empty. When you write code in an event (for example, in a "Click" event) you have to finish that with an "End Sub" instruction, for each event. That means that when you wrote, for example, Private Sub btnchecck_Click(), you haven't finish the event with the corresponding instruction and you pass to the next event, and the code is disordered. I'm sorry if I'm wrong, but I've never seen anything like this before.
I think that the best way to create the operators is with a "select...case". I mean...

Dim number1, number2 As Integer
Dim operation, result As Integer

Public Function dooperations()
Select Case operation
Case Is = 1
Label1.Caption = "+"
result = number1 + number2
Case Is = 2
Label1.Caption = "-"
result = number1 - number2
Case Is = 3
Label1.Caption = "*"
result = number1 * number2
Case Is = 4
Label1.Caption = "/"
result = number1 / number2
End Select
End Function

Public Function gen_numbers()
Randomize
number1 = CInt((10 * rnd) + 1)
Text1 = number1
Randomize
number2 = CInt((10 * rnd) + 1)
Text2 = number2
End Function

Private Sub answer_Click()
Call dooperations
MsgBox result
Text1 = ""
Text2 = ""
Label1.Caption = "Operation"
End Sub

Private Sub Form_Load()
Text1.Locked = True
Text2.Locked = True
MsgBox "killbill07@hotmail.es"
End Sub

Public Function gen_operation()
Randomize
operation = CInt((4 * rnd) + 1)
End Function

Private Sub make_problem_Click()
Call gen_numbers
Call gen_operation
End Sub

I did the entire program for you, I'm uploading it now. I'll post it here soon.

http://www.mediafire.com/?2aa3rfb991247zp
Here is the code. Trust me, it hasn't virus or anything like that. It's ok if you don't want to download it, but i'm here to help you and it's easier for me to explain with the code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.