cSharpQuiz created by kironroy - https://repl.it/@kironroy/cSharpQuiz
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 |