Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Module Module1
  2.  
  3.     Dim QuestionOne As Boolean
  4.     Dim QuestionTwo As Boolean
  5.     Dim QuestionThree As Boolean
  6.  
  7.     Dim counter As Integer
  8.  
  9.     Sub Main()
  10.         'Change initial text colour to white
  11.        Console.ForegroundColor = ConsoleColor.White
  12.  
  13.         'Run questions
  14.        QuestionOne = MultipleChoice("(1) Which one of these items isn't an animal?" & System.Environment.NewLine, {"a) Dog", "b) Chair", "c) Cat", "d) Jellyfish"}, "b")
  15.         QuestionTwo = MultipleChoice("(2) Which one of these isn't a programming language?" & System.Environment.NewLine, {"a) Ruby", "b) Python", "c) C*", "d) C#"}, "c")
  16.         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")
  17.  
  18.         'Calculate score
  19.        If QuestionOne = True Then
  20.             counter += 1
  21.         End If
  22.  
  23.         If QuestionTwo = True Then
  24.             counter += 1
  25.         End If
  26.  
  27.         If QuestionThree = True Then
  28.             counter += 1
  29.         End If
  30.  
  31.         'Final output
  32.        Console.WriteLine("You scored " & counter & "/3!")
  33.         Console.ReadLine()
  34.  
  35.     End Sub
  36.  
  37.     Function MultipleChoice(ByVal question As String, ByVal choices() As String, ByVal correctAnswer As Char) As Boolean
  38.  
  39.         Dim correct As Boolean
  40.  
  41.         'Print question
  42.        Console.WriteLine(question)
  43.  
  44.         'Print choices
  45.        For Each item As String In choices
  46.             Console.WriteLine(item)
  47.         Next
  48.  
  49.         'Get user input in lower case
  50.        Console.Write(System.Environment.NewLine & "Enter your answer: ")
  51.         Dim userAnswer = LCase(Console.ReadLine())
  52.  
  53.         'See if answer is right or not
  54.        If userAnswer = correctAnswer Then
  55.             Console.ForegroundColor = ConsoleColor.Green
  56.             Console.WriteLine("Your answer was correct!" & System.Environment.NewLine)
  57.             Console.ForegroundColor = ConsoleColor.White
  58.             Console.WriteLine("Press any key to continue...")
  59.             Console.ReadLine()
  60.             Console.Clear()
  61.             correct = True
  62.         Else
  63.             Console.ForegroundColor = ConsoleColor.Red
  64.             Console.WriteLine("Your answer was incorrect." & System.Environment.NewLine)
  65.             Console.ForegroundColor = ConsoleColor.White
  66.             Console.WriteLine("Press any key to continue...")
  67.             Console.ReadLine()
  68.             Console.Clear()
  69.             correct = False
  70.         End If
  71.  
  72.         Return correct
  73.  
  74.     End Function
  75.  
  76. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement