-
-
Save codecademydev/7d90be874412918a23732bb70ec78e45 to your computer and use it in GitHub Desktop.
Codecademy export
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; | |
namespace TrueOrFalse | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Welcome to 'True or False?'\nPress Enter to begin:"); | |
string entry = Console.ReadLine(); | |
Tools.SetUpInputStream(entry); | |
string[] questions = { "Eggplants are a type of berry.", "Peanuts are not nuts!", "Copyrights depreciate over time.", "Emus can’t fly.", "Electrons move faster than the speed of light.", "Light travels in a straight line.", "People may sneeze or cough while sleeping deeply.", "There is no snow on Minecraft." }; | |
bool[] answers = { true, true, true, true, false, true, false, false }; | |
bool[] responses = new bool[questions.Length]; | |
if (questions.Length != answers.Length) | |
{ | |
Console.WriteLine("The number of questions doesn't mathc the number of answers."); | |
} | |
int askingIndex = 0; | |
foreach (string question in questions) | |
{ | |
Console.WriteLine(question); | |
Console.WriteLine("True or false?"); | |
bool isBool = false; | |
while(!isBool) | |
{ | |
string input = Console.ReadLine(); | |
isBool = Boolean.TryParse(input, out bool inputBool); | |
if (!isBool) { Console.WriteLine("Please respond with 'true' or 'false'."); } | |
else { responses[askingIndex ++] = inputBool; } | |
} | |
} | |
int scoringIndex = 0; | |
int score = 0; | |
foreach (bool answer in answers) | |
{ | |
bool response = responses[scoringIndex ++]; | |
Console.WriteLine($"{scoringIndex}. Input: {response} | Answer: {answer}"); | |
if (response == answer) { score ++; } | |
} | |
Console.WriteLine($"You got {score} out of {scoringIndex} correct!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment