Created
October 12, 2018 14:20
-
-
Save kironroy/36f79aacdd68a7ef8a886f2603a8b6d7 to your computer and use it in GitHub Desktop.
cSharpQuiz created by kironroy - https://repl.it/@kironroy/cSharpQuiz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
namespace CSharpQuiz | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// define variables | |
var cSharpwelcomePrompt = "Welcome to c++ quiz "; | |
var correctAnswer = "Correct!\n"; | |
var wrongAnswer = "Wrong!\n"; | |
var quizAnswers = " Quiz answers:\n\n 1. 2002\n 2. Anders Hejlsberg\n 3. True, C# is compiled"; | |
Console.WriteLine("What is your name"); | |
var nameInput = Console.ReadLine().Trim(); | |
var nameInputCaps = new CultureInfo("en-US").TextInfo.ToTitleCase(nameInput); | |
BreakLine(); | |
Console.WriteLine($"Hello {nameInputCaps} {cSharpwelcomePrompt}"); | |
// question 1 | |
Console.WriteLine("1. When was C# created? (Type a year)"); | |
var quizQuestion1 = Console.ReadLine().Trim(); | |
if (quizQuestion1 == "2002") | |
{ | |
Console.WriteLine(correctAnswer); | |
} | |
else | |
Console.WriteLine(wrongAnswer); | |
BreakLine(); | |
// question 2 | |
Console.WriteLine("2. What is the first name of C#'s creator"); | |
var quizQuestion2 = Console.ReadLine().Trim().ToLower(); | |
if (quizQuestion2 == "anders") | |
{ | |
Console.Write(correctAnswer); | |
BreakLine(); | |
} | |
else | |
Console.WriteLine(wrongAnswer); | |
BreakLine(); | |
// question 3 | |
Console.WriteLine("True or false: is C# compiled?, type true or false"); | |
var quizQuestion3 = Console.ReadLine().Trim().ToLower(); | |
if (quizQuestion3 == "true") | |
{ | |
Console.WriteLine(correctAnswer); | |
} | |
else | |
Console.WriteLine(wrongAnswer); | |
BreakLine(); | |
Console.WriteLine(quizAnswers); | |
} // main function ending bracket | |
// breakline method | |
private static void BreakLine() | |
{ | |
Console.WriteLine(); | |
} | |
} // class Program ending bracket | |
} // namespace ending bracket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MZ� �� � @ � � � �!�L�!This program cannot be run in DOS mode. | |
$ PE L � �' |