I have been struggling with this for 4 days - Please help. I have attached a copy of my code with the hope that someone here can give me some insight as to what I am missing. (This is a homework assignment, so please keep that in mind. I am not looking for someone to do my work for me, but instead, to provide guidance.)
Brief Overview of project:
Simple math quiz that presents 10 multiplication problems and tallys the results to be displayed at the end. Each problem has 5 seconds to be completed before it is counted as incorrect and the program moves on to the next.
Issues:
1. I have a timer attached to math problems that counts down from 5 seconds for each, but when the timer runs out it does not add to the incorrect answer tally.
- My If statement is set to stop presenting new questions after the 10th and to display the results, however it continues to present new problems.
My code:
Option Explicit On
Option Strict On
Option Infer Off
Public Class frmMain
Dim intTimeLeft, intCorrect, intInCorrect As Integer
Private Sub GenerateAndDisplayIntegers()
' generates and displays two random integers
Dim intRandom1, intRandom2 As Integer
Dim randomGenerator As New Random
' generate random integers
intRandom1 = randomGenerator.Next(1, 10)
intRandom2 = randomGenerator.Next(1, 10)
' display integers
lblNum1.Text = Convert.ToString(intRandom1)
lblNum2.Text = Convert.ToString(intRandom2)
txtAnswer.Text = String.Empty
intTimeLeft = 5
lblTimer.Text = intTimeLeft.ToString
tmrAnswer.Start()
End Sub
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
' starts math test
Call GenerateAndDisplayIntegers()
intTimeLeft = 5
lblTimer.Text = intTimeLeft.ToString
tmrAnswer.Start()
End Sub
Private Sub btnAnswer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAnswer.Click
' calculates the correct answer and then compares the correct answer to the user's answer
' keeps track of the number of correct and incorrect responses
Dim x, intNum1, intNum2, intUserAnswer, intCorrectAnswer As Integer
x = 1
If x < 10 Then
Integer.TryParse(lblNum1.Text, intNum1)
Integer.TryParse(lblNum2.Text, intNum2)
Integer.TryParse(txtAnswer.Text, intUserAnswer)
intCorrectAnswer = intNum1 * intNum2
If intUserAnswer = intCorrectAnswer Then
intCorrect += 1
ElseIf intTimeLeft > 0 Then
intInCorrect = intInCorrect + 1
Else
intCorrect = intCorrect + 1
End If
Call GenerateAndDisplayIntegers()
x = x + 1
Else
lblNum1.Text = String.Empty
lblNum2.Text = String.Empty
txtAnswer.Text = String.Empty
lblTimer.Text = "Done"
lblCorrect.Text = intCorrect.ToString
lblIncorrect.Text = intInCorrect.ToString
End If
End Sub
Private Sub tmrAnswer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAnswer.Tick
If intTimeLeft > 0 Then
intTimeLeft -= 1
lblTimer.Text = intTimeLeft.ToString
'Else
tmrAnswer.Stop()
' txtAnswer.Text = String.Empty
' Call GenerateAndDisplayIntegers()
' intTimeLeft = 5
' lblTimer.Text = intTimeLeft.ToString
' tmrAnswer.Start()
End If
End Sub
End Class