repl.it
@kironroy/

cSharpQuiz-1

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
  • notes.txt
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Globalization;

namespace CSharpQuiz {
 class Program {
  static void Main(string[] args) {

   string myChoice;

   do {
      
      Console.WriteLine();
      Console.WriteLine("Welcome to C# quiz");
      Console.WriteLine("");
      Console.WriteLine("S - Start Quiz");
      Console.WriteLine("Q - Quit\n");
      Console.WriteLine("Choose S or Q: ");
 
      
      // Retrieve the user's choice
      myChoice = Console.ReadLine().ToUpper();
      switch (myChoice) {
      case "S":
      Console.WriteLine();
      Console.WriteLine("Let's Go!");
      
      string[] quizPrompts = new string[] {"good luck with the quiz! ", "Correct!\n ", "Wrong!\n "," Quiz answers:\n\n 1. 2002\n 2. Anders Hejlsberg\n 3. True, C# is compiled ", "good luck with the quiz! " };

      string name = GetInfoFromConsole("What is your name");
      Console.WriteLine();
      Console.WriteLine($"Hello {name} {quizPrompts[4]}");
      Console.WriteLine();

      // question 1

      string quizQuestion1 = GetInfoFromConsole("1. When was C# created? (Type a year)");
      
      if (quizQuestion1 == "2000") {
       Console.WriteLine(quizPrompts[1]);
      } else
       Console.WriteLine(quizPrompts[2]);
       Console.WriteLine("");

     

      // question 2

      string quizQuestion2 = GetInfoFromConsole("2. What is the first name of C#'s creator");
      
      if (quizQuestion2 == "Anders") {
        Console.WriteLine(quizPrompts[1]);
      } else
       Console.WriteLine(quizPrompts[2]);
       Console.WriteLine("");



      // question 3
      
      string quizQuestion3 = GetInfoFromConsole("True or false: is C# compiled?, type true or false");
      if (quizQuestion3 == "True") {
       Console.WriteLine(quizPrompts[1]);
      } else
       Console.WriteLine(quizPrompts[2]);
       Console.WriteLine("");

      Console.WriteLine(quizPrompts[3]);
      break;
     case "Q":
      Console.WriteLine("Keep practicing!");
      break;
     default:
      Console.WriteLine("\n{0} is not a valid choice", myChoice);
      break; 

    } // do's end bracket
   } while (myChoice != "Q"); // users quits



  } // main function ending bracket

  // breakline method
 
  public static string GetInfoFromConsole(string message)
    {
        string output = "";

        Console.Write(message);
        output = Console.ReadLine().Trim();
        string outputCaps = new CultureInfo("en-US").TextInfo.ToTitleCase(output);

        return outputCaps;
    }

 } // class Program ending bracket

} // namespace ending bracket