Skip to content

Instantly share code, notes, and snippets.

@codecademydev

codecademydev/Program.cs Secret

Created Mar 21, 2020
Embed
What would you like to do?
Codecademy export
using System;
namespace TrueOrFalse
{
class Program
{
static void Main(string[] args)
{
// Do not edit these lines
Console.WriteLine("Welcome to 'True or False?'. Let's begin!");
//string entry = Console.ReadLine();
//Tools.SetUpInputStream(entry);
// Type your code below
string[] questions = {"hello is pronounced the same as Hello", "3.5 = 3 + 1/2", "The square root of 1 = -1", "Tik Tok is an app", "Your are responsible for your own life", "LionKing is not a classic", "5 + 5 = 0.1"};
bool[] answers = {true, true, false, true, true, false, false};
bool[] responses = new bool[questions.Length];
if (questions.Length != answers.Length) {
Console.WriteLine("ERROR! Your questions array length is not equal to your answers array length (the quantity of your questions is not the same as the quantity of your answers!)");
}
int askingIndex = 0;
foreach (string question in questions) {
string input = "";
bool isBool = false;
bool inputBool = true;
Console.WriteLine(question);
Console.WriteLine("True or False?");
input = Console.ReadLine();
isBool = Boolean.TryParse(input, out inputBool);
while (isBool == false) {
Console.WriteLine("Please respond with 'true' or 'false'.");
input = Console.ReadLine();
isBool = Boolean.TryParse(input, out inputBool);
}
responses[askingIndex] = inputBool;
askingIndex++;
}
int scoringIndex = 0;
int score = 0;
foreach (bool answer in answers) {
bool response = responses[scoringIndex];
Console.WriteLine((scoringIndex + 1) + " Input: " + response + " | Answer: " + answer);
if (response == answer) {
score++;
}
scoringIndex++;
}
Console.WriteLine("You got " + score + " out of " + questions.Length);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment