Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Dim QuestionOne As Boolean
- Dim QuestionTwo As Boolean
- Dim QuestionThree As Boolean
- Dim counter As Integer
- Sub Main()
- 'Change initial text colour to white
- Console.ForegroundColor = ConsoleColor.White
- 'Run questions
- QuestionOne = MultipleChoice("(1) Which one of these items isn't an animal?" & System.Environment.NewLine, {"a) Dog", "b) Chair", "c) Cat", "d) Jellyfish"}, "b")
- QuestionTwo = MultipleChoice("(2) Which one of these isn't a programming language?" & System.Environment.NewLine, {"a) Ruby", "b) Python", "c) C*", "d) C#"}, "c")
- QuestionThree = MultipleChoice("(3) Which of the following is not a prime number?" & System.Environment.NewLine, {"a) 16", "b) 23", "c) 31", "d) 101", "e) 233"}, "a")
- 'Calculate score
- If QuestionOne = True Then
- counter += 1
- End If
- If QuestionTwo = True Then
- counter += 1
- End If
- If QuestionThree = True Then
- counter += 1
- End If
- 'Final output
- Console.WriteLine("You scored " & counter & "/3!")
- Console.ReadLine()
- End Sub
- Function MultipleChoice(ByVal question As String, ByVal choices() As String, ByVal correctAnswer As Char) As Boolean
- Dim correct As Boolean
- 'Print question
- Console.WriteLine(question)
- 'Print choices
- For Each item As String In choices
- Console.WriteLine(item)
- Next
- 'Get user input in lower case
- Console.Write(System.Environment.NewLine & "Enter your answer: ")
- Dim userAnswer = LCase(Console.ReadLine())
- 'See if answer is right or not
- If userAnswer = correctAnswer Then
- Console.ForegroundColor = ConsoleColor.Green
- Console.WriteLine("Your answer was correct!" & System.Environment.NewLine)
- Console.ForegroundColor = ConsoleColor.White
- Console.WriteLine("Press any key to continue...")
- Console.ReadLine()
- Console.Clear()
- correct = True
- Else
- Console.ForegroundColor = ConsoleColor.Red
- Console.WriteLine("Your answer was incorrect." & System.Environment.NewLine)
- Console.ForegroundColor = ConsoleColor.White
- Console.WriteLine("Press any key to continue...")
- Console.ReadLine()
- Console.Clear()
- correct = False
- End If
- Return correct
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement