Math help

  • Thread starter Thread starter DoRJo
  • Start date Start date
D

DoRJo

Guest
This question has been asked 100 times. I know, I have read thru all of them but I can not decipher which answer is best or why the answers will not work for my application.

I am creating a random math generator. I have solved each issue except how to get a whole number as an answer when dividing (i.e., 10 / 2 = 5 or 20 / 4 = 5). I have tried If-Then statements, Do Loops, Boolean with MOD = 0 but get "dividing by zero error. As well, I have tried changing the problem around but nothing seems to work. Any help is greatly appreciated or pointing to more reading material that I may have missed.

Public Class Form1
'Generate random numbers
Public Generator As New Random
'Generate random operators
Dim Operators As String() = New String() {"+", "-", "x", "÷"}
Dim Sign As New Random
'Variables
Public var1 As Integer
Public var2 As Integer
'Answer
Dim number As Integer
Public Sub Sum()
'Start Application/Add New Math Problem
var1 = Generator.Next(21)
var2 = Generator.Next(21)

'Convert numbers to string
lblLeft.Text = var1.ToString()
lblRight.Text = var2.ToString()

Dim rndOper = Sign.Next(0, 4)
lblOperator.Text = Operators(rndOper)

Select Case rndOper
Case 0
number = var1 + var2
Case 1
number = var1 - var2
Case 2
number = var1 * var2
Case 3
number = var1 / var2
End Select

If var1 > var2 = False Then
Sum()
End If

Label1.Text = number.ToString()

End Sub

Continue reading...
 
Back
Top