# Need help creating a simple math quiz (Visual Basic)

I am a fairly new programmer and I am looking for some help with my current task. I am trying to create a program that generates 2 random numbers and a random operator and then asks the user for an answer. I think I did this part.

However, when I try to get the program to display the correct answer, it just shows the problem and doesn't answer the question with the correct answer.

Any help is greatly appreciated!

``````Module Module1

Sub Main()
Randomize()
Dim RandomNum As New Random

Dim Number1 As Integer
Dim Number2 As Integer
Dim Operation As Integer
Dim Output As String

Number1 = RandomNum.Next(1, 20)
Number2 = RandomNum.Next(1, 20)
Operation = RandomNum.Next(1, 4)

If (Operation = 1) Then
Output = " + "
ElseIf (Operation = 2) Then
Output = " - "
ElseIf (Operation = 3) Then
Output = " * "
Else
Output = " / "
End If

Console.WriteLine("What is " & Number1 & Output & Number2 & "?")

Console.WriteLine("The correct answer is " & Number1 & Output & Number2) <------ Here is where the problem is

End Sub

End Module
```

```
+3

source to share

``````Dim correctAnswer as Single
```

```

and then change to the following:

``````If (Operation = 1) Then
Output = " + "
ElseIf (Operation = 2) Then
Output = " - "
ElseIf (Operation = 3) Then
Output = " * "
Else
Output = " / "
End If
```

```

and finally change to:

``````Console.WriteLine("The correct answer is " & correctAnswer)
```

```
+2

source

May I also assume that you are using a Select statement instead of sequential If-Else statements. Like this:

``````Dim Answer as Decimal

Select Case (Operation)
Case 1
Output = " + "
Case 2
Output = " - "
Case 3
Output = " * "
Case Else
Output = " / "
End Select
```

```
+1

source

All Articles