Math Game

G

Guest

I have teo buttons ont the display the problem and for the user to submit the
answer, but it is not comparing the user's answer
Private Sub btnNQuestion_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNQuestion.Click
num1 = rand.Next(1, 15)
num2 = rand.Next(1, 15)
Dim sr As StreamReader
Dim sw As StreamWriter
Dim ans As String

If rbtnAdd.Checked Then
lblQuestion.Text = num1.ToString() & "+" & num2.ToString()
ElseIf rbtnSubtract.Checked Then
lblQuestion.Text = num1.ToString() & "-" & num2.ToString()

End If
txtanswer.Clear()
End Sub

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Dim ans As Integer
ans = (num1 + num2)
ans = (num1 - num2)

If ans = txtanswer.Text Then
lblNofQ.Text = "correct"
Else
lblNofQ.Text = "Incorrect"
End If
End Sub
End Class
 
O

One Handed Man \( OHM - Terry Burns \)

In your submit function, you seem to set asn twice?!?

ans = (num1 + num2)
ans = (num1 - num2)


And Here, you are trying to compare an integer with a string, try

ans.ToString() = txtanswer.Text Then



If ans = txtanswer.Text Then
lblNofQ.Text = "correct"
Else
lblNofQ.Text = "Incorrect"
End If

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
J

Jacob Thastrup

Just use a bit of the code you used above:

If rbtnAdd.Checked Then
ans = num1 + num2
Else
If rbtnSubtract.Checked Then
ans = num1 - num2
End if
End if

That should work

see ya

Jacob
 
G

Guest

here is my complete code. I am suppose to 1.display a problem and compare the
2.users answer and save it to a text file, but I can not past 2
any help- please
 
O

One Handed Man \( OHM - Terry Burns \)

Private Sub newQuestionButton_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles newQuestionButton.Click
Dim r As New Random
txtOp1.Text = r.Next(1, 15)
txtOp2.Text = r.Next(1, 15)
lblAns.Text = ""
txtAns.Clear()


End Sub

Private Sub submitButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles submitButton.Click


'Get Answer
Dim answer As Integer

If Me.radAdd.Checked Then

answer = Convert.ToInt32(txtOp1.Text) +
Convert.ToInt32(txtOp2.Text)
Else
answer = Convert.ToInt32(txtOp1.Text) -
Convert.ToInt32(txtOp2.Text)
End If

Try

If answer = Convert.ToInt32(txtAns.Text) Then
lblAns.Text = "Correct"
Else
lblAns.Text = "Wrong, amnswer was " & answer.ToString
End If



Catch ex As ArgumentOutOfRangeException
lblAns.Text = ex.Message
Catch ex As Exception
lblAns.Text = ex.Message
End Try

End Sub


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top