This is a math quiz game. It uses multiplication, but you can change it to any operation in the LoadQuestions sub.
Code:
Option Strict On
Option Explicit On
Module Module1
Private r As New Random
Sub Main()
Call LoadQuestions()
Do Until True = False
Dim exclusive_numbers() As Integer = Enumerable.Range(0, 9).OrderBy(Function(n) r.Next(10)).ToArray
For i As Integer = 0 To questions.Count - 1
Dim item As Question = questions.Item(exclusive_numbers(i))
Console.WriteLine(item.Text)
Dim _numbers() As Integer = Enumerable.Range(0, 4).OrderBy(Function(n) r.Next(5)).ToArray
For Each x As Integer In _numbers
If x = 0 Then
Console.WriteLine(item.Answer)
ElseIf x = 1 Then
Console.WriteLine(item.Fake1)
ElseIf x = 2 Then
Console.WriteLine(item.Fake2)
Else
Console.WriteLine(item.Fake3)
End If
Next
Console.WriteLine()
Dim response As String = Console.ReadLine
If response = item.Answer Then
Console.WriteLine("That is correct.")
Else
Console.WriteLine("You got that one wrong.")
End If
Console.WriteLine()
Next
Loop
End Sub
Private questions As New List(Of Question)
Private Sub LoadQuestions()
'Just a bunch of random questions and answers:
For i As Integer = 1 To 10
Dim q As New Question
'Get an unique list of numbers from 1 - 10
Dim exclusive_numbers() As Integer = Enumerable.Range(1, 10).OrderBy(Function(n) r.Next(11)).ToArray
'Setup the question
With q
.Text = String.Format("What is {0} * {1}?", i, exclusive_numbers(0))
.Answer = CStr(i * exclusive_numbers(0))
.Fake1 = CStr(i * exclusive_numbers(1))
.Fake2 = CStr(i * exclusive_numbers(2))
.Fake3 = CStr(i * exclusive_numbers(3))
End With
'Add it to the list
questions.Add(q)
Next
End Sub
End Module
Public Class Question
Private txt As String
Public Property Text() As String
Get
Return txt
End Get
Set(ByVal value As String)
txt = value
End Set
End Property
Private m_answer As String
Public Property Answer() As String
Get
Return m_answer
End Get
Set(ByVal value As String)
m_answer = value
End Set
End Property
Private m_fake1 As String
Public Property Fake1() As String
Get
Return m_fake1
End Get
Set(ByVal value As String)
m_fake1 = value
End Set
End Property
Private m_fake2 As String
Public Property Fake2() As String
Get
Return m_fake2
End Get
Set(ByVal value As String)
m_fake2 = value
End Set
End Property
Private m_fake3 As String
Public Property Fake3() As String
Get
Return m_fake3
End Get
Set(ByVal value As String)
m_fake3 = value
End Set
End Property
Public Sub New()
txt = String.Empty
m_answer = String.Empty
m_fake1 = String.Empty
m_fake2 = String.Empty
m_fake3 = String.Empty
End Sub
Public Sub New(ByVal question As String, ByVal answer As String, ByVal fake1 As String, ByVal fake2 As String, ByVal fake3 As String)
txt = question
m_answer = answer
m_fake1 = fake1
m_fake2 = fake2
m_fake3 = fake3
End Sub
End Class