True or False? C# project - user input not registered correctly


I got stuck at the ‘True or False?’ project since when the code runs all of the responses (user inputs) are show as ‘True’ (instead of ‘True’ or ‘False’ depending on the input) and that leads to the score not updating properly.

I followed the solution as well, step by step, but the problem still persists. It just drives me crazy. Where is the mistake? Thanks in advance.

Here’s the code below:

using System; namespace TrueOrFalse { class Program { static void Main(string[] args) { // Do not edit these lines Console.WriteLine("Welcome to 'True or False?'\nPress Enter to begin:"); string entry = Console.ReadLine(); Tools.SetUpInputStream(entry); string[] questions = new string[] { "Eggplants are a type of berry?", "Aliens are real?", "Is tomato a fruit?" }; bool[] answers = new bool[] { true, false, true }; bool[] responses = new bool[questions.Length]; if (questions.Length != answers.Length) { Console.WriteLine($"Warning. Restart the program."); } int askingIndex = 0; foreach (string question in questions) { string input; bool isBool; bool inputBool; Console.WriteLine(question); Console.WriteLine("True or False?"); input = Console.ReadLine(); isBool = Boolean.TryParse(input, out inputBool); while(!isBool) { Console.WriteLine($"Please respond with 'true' or 'false'"); input = Console.ReadLine(); isBool = Boolean.TryParse(input, out inputBool); } responses[askingIndex] = isBool; askingIndex++; } int scoringIndex = 0; int score = 0; foreach (bool answer in answers) { bool response = responses[scoringIndex]; Console.Write(scoringIndex + 1 + "."); Console.WriteLine($"Input: {response} | Answer: {answer}"); if (response == answer){ score++; } scoringIndex++; } Console.WriteLine($"You got {score} out of {questions.Length} correct."); } } }

I’m not sure what’s going on here, but in your answers section:

bool[] answers = new bool[] 

it has the same order of true false true. Could it be taking that instead of processing the inputs as intended?

If you are still looking for an answer, the problem is with line 57.

You are saving the isBool value (which tells if the value entered by the user is a boolean or not - and which will always be true) and not inputBool, which is the value the user has entered.

Thank you very much. You were correct!

I probably was too tired, that I missed that mistake at line 57.