You are on page 1of 3

Task 3:

Sub Main()
Dim TotalQuestions As Integer
Dim Questions As Integer
Dim TableChoice As Integer
Dim StudentAnswer As Integer
Dim RandomNumber As Integer
Dim Score As Integer
Dim StudentName As String
Dim StudentAttempts As Integer
Dim CorrectAnswer As Boolean
Dim MixedSet As Boolean
TableChoice = 0
StudentAttempts = 0
CorrectAnswer = False
MixedSet = False
Console.WriteLine("Enter your name")
StudentName = Console.ReadLine()
Console.WriteLine("How many questions would you like?")
TotalQuestions = Console.ReadLine()
Console.WriteLine("Would you like a Mixed Set?")
MixedSet = Console.ReadLine()
If MixedSet = False Then
While TableChoice < 1 Or TableChoice > 12
Console.WriteLine("Enter a number between 2 and 12")
TableChoice = Console.ReadLine()
End While
End If
For Questions = 1 To TotalQuestions
RandomNumber = 12 * Rnd()
If MixedSet = True Then
TableChoice = 12 * Rnd()
End If
While StudentAttempts < 3 And CorrectAnswer = False
Console.WriteLine("What is " & TableChoice & " X " & RandomNumber)
StudentAnswer = Console.ReadLine()
If StudentAnswer = TableChoice * RandomNumber Then
Score = Score + 1
Console.WriteLine(StudentName & " your answer is correct")
CorrectAnswer = True
End If
If StudentAnswer > TableChoice * RandomNumber Then
Console.WriteLine(StudentName & " your answer is too large.")
ElseIf StudentAnswer < TableChoice * RandomNumber Then
Console.WriteLine(StudentName & " your answer is too small.")
End If
StudentAttempts = StudentAttempts + 1
End While
If CorrectAnswer = False Then
Console.WriteLine("The correct answer is " & TableChoice * RandomNumber)
End If
CorrectAnswer = False
StudentAttempts = 0
Next
Console.WriteLine(StudentName & " your score is " & Score & " /" & TotalQuestions)
If Score = TotalQuestions Then
Console.WriteLine("Well done full marks")
Else
Console.WriteLine("Have another practise")
End If
Console.ReadLine()
End Sub
End Module

You might also like