Basic Arithmetic ???

d33f3r
d33f3r used Ask the Experts™
on
I'm trying to create a program that randomly generates 2 numbers between 1 & 12, as well as an addition/multiply statement, works out the answer but waits for the user to input their answer, check it against the working and if its correct display a msg, incorrect displays a different msg and prompts the user to try again until it gets it right. *breath*
I also need some kind of counter that counts the number of 1st time corrects and incorrects.  This counter is needed for when the user exits the program it should display a percentage of corrects...  E-z ?  I'd like to think so.. help me!!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Sounds like a school assignment to me.  Other than writing the whole program what specifically do you need help with?
Project manager
Commented:
Dim correctCount As Integer
Dim wrongCount As Integer
Dim correct As Integer

Private Sub Command1_Click()

    correct = IIf(Text3.Text = "+", CInt(Text1.Text) + CInt(Text2.Text), CInt(Text1.Text) * CInt(Text2.Text))
    If correct = CInt(Text4.Text) Then
        correctCount = correctCount + 1
        answer = MsgBox("Correct. Try another ?", vbYesNo)
        If answer = vbYes Then
            randomnumber
        Else
            MsgBox ("Correct numbers: " & correctCount & ", wrong numbers:" & wrongCount)
            Unload Me
        End If
    Else
        wrongCount = wrongCount + 1
        answer = MsgBox("Wrong answer. Try again ?", vbYesNo)
        If answer = vbNo Then
            MsgBox ("Correct numbers: " & correctCount & ", wrong numbers:" & wrongCount)
            Unload Me
        End If
    End If
End Sub

Private Sub Form_Load()
    wrongCount = 0
    correctCount = 0
    randomnumber
End Sub

Private Function randomnumber()
    Text1.Text = Int((12 * Rnd) + 1)
    Text2.Text = Int((12 * Rnd) + 1)
    Text3.Text = IIf(Round(Rnd) = 0, "+", "*")
    Text4.Text = 0
    Text1.Locked = True
    Text2.Locked = True
    Text3.Locked = True
End Function

' Checking that the user can only give numbers
Private Sub Text4_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
      Case 48 To 57, 8, 47, 46
      Case Else
        KeyAscii = 0
    End Select
End Sub


It's a simple form with 4 textboxes and 1 command button

Commented:
Hmmm... Beaten to it:

Public No1 As Integer, No2 As Integer
Public Operator As String
Public OpGenerator As Integer
Public UserAnswer As Variant
Public Answer As Integer
Public More As VbMsgBoxResult
Public Corrects As Integer
Public Wrongs As Integer
Public FirstGo As Boolean

Public Sub GenNos()
No1 = Int(12 * Rnd() + 1)
No2 = Int(12 * Rnd() + 1)
OpGenerator = Int(2 * Rnd() + 1)
End Sub

Public Sub askQ()
If OpGenerator = 1 Then
    Operator = "+"
    Answer = No1 + No2
End If
If OpGenerator = 2 Then
    Operator = "*"
    Answer = No1 * No2
End If
Do
    UserAnswer = InputBox("Give me the answer to " & CStr(No1) & " " & Operator & " " & CStr(No2), "Maths Question")
    If IsNumeric(UserAnswer) = False Then MsgBox "Please give a numeric answer"
Loop Until IsNumeric(UserAnswer) = True

End Sub

Private Sub CommandButton1_Click()

Call GenNos
Call askQ
FirstGo = True
Corrects = 0
Wrongs = 0
Do
    If UserAnswer = Answer Then
        More = MsgBox("Correct answer, would you like to try another one?", vbYesNo, "More?")
        If FirstGo = True Then Corrects = Corrects + 1
        If More = vbYes Then
            Call GenNos
            Call askQ
        End If
    Else
        More = MsgBox("Wrong answer! would you like to try again?", vbYesNo, "Another go?")
        If FirstGo = True Then Wrongs = Wrongs + 1
        If More = vbYes Then
            FirstGo = False
            Call askQ
        End If
        If More = vbNo Then
            More = MsgBox("Would you like to try another one?", vbYesNo, "More?")
            If More = vbYes Then
                FirstGo = True
                Call GenNos
                Call askQ
            End If
        End If
    End If
Loop Until More = vbNo

MsgBox "You Got " & Int((Corrects / (Wrongs + Corrects)) * 100) & "% Correct!"
   
End Sub
Author of the Year 2009

Commented:
Hi d33f3r,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Dhaest's comment(s) as an answer.

d33f3r, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer

Commented:
I have just recieved an e-mail reiterating that d33f3r has not closed this question.  But as I'm not s/he, it has gone to the wrong address.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial