True or False

Hey I was wondering if someone could explain why I can’t get all three of my questions to be executed. I have to run the code once for every question…yours truly - Billy mcFartnuggets.

string questions = {“the sky is blue?”, “there are seven days in a week”, “girls can’t fart”};
bool answers = {true, true, false };
bool responses = new bool[3];

  if (questions.Length != answers.Length)    
  {
    Console.WriteLine("questions and answers do not match");
  }
  
 int askingIndex = 0; 
  
 foreach (string question in questions)
 {
  string input;
  bool replyAsBool;
  bool isBool;
 
  {Console.WriteLine($" {questions[0]}. Please respond true or false");

Console.ReadLine();
string reply = Console.ReadLine();
}
{Console.WriteLine(" {questions[1]}. Please respond true or false"); Console.ReadLine(); string reply2 = Console.ReadLine(); } {Console.WriteLine(" {questions[2]}. Please respond true or false");
Console.ReadLine();
string reply3 = Console.ReadLine();
}
isBool = Boolean.TryParse(reply, out replyAsBool);

}

hello, im doing this exercise right now and was stuck on the same thing.
what i changed when stuck at step 10

using System;

namespace TrueOrFalse
{
  class Program
  {
		static void Main(string[] args)
    {
      // Do not edit these lines
      Console.WriteLine("Welcome to 'True or False?'\nPress any key to begin:");
      string entry = Console.ReadLine();
      Tools.SetUpInputStream(entry);

      // Type your code below
      //string array of questions
      string[] questions = new string[] { "is shaen alpha? ", "is yul a trash silver?", "is guillaume plat on tft? " };
      //bool array of answers to question[]
      bool[] answers = new bool[] { false, false, true };
      //bool array of responses user write
      bool[] responses = new bool[questions.Length];
      
      //warning if too much answers compared to questions
      if (questions.Length != answers.Length)
      {
        Console.WriteLine("the number of answers doesn't match the number of answers, retry");
      }
      
      int askingIndex = 0;
      
      foreach (string question in questions)
      {
        string input;
        bool isBool;
        bool inputBool;
        
        Console.WriteLine(question, "true or false?");
        input = Console.ReadLine();
        
        isBool = Boolean.TryParse(input, out inputBool);
      }
      
      
      
    }
  }
}

when you’re in your foreach loop and you need to print your questions from questions array. You build your loop saying “for each QUESTION in questions”. question is string type, that means that foreach will look for string values in your questions array. Everytime foreach find a string in questions, it will print it to the console.

Thats why you just need Console.WriteLine(question, “true or false?”); when you want to print each question one after another.

You might already found the answer yourself but maybe it will help someone else. Also im a total noob to coding so this is how i understand it, but if anyone has a better explanation and/or way to do it i’ll be glad to read it !

Leave one kind of solution here for this exercise.

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);

      // Type your code below
      string[] questions = {"¿Do i live in Spain?", "¿Do i have 40 years?"};
      bool[] answers = {true,false};
      bool [] responses = new bool [questions.Length];
            
      int askingIndex = 0;
      foreach(var pregunta in questions )
      {
       
        bool isBool;
        bool inputBool;        
        Console.WriteLine(pregunta,"True or False");
        // Valida si el input del usuario se puede transformar a booleano y si no entra en el loop. El out le asigna un valor a la variable inputBool
        while (!Boolean.TryParse(Console.ReadLine(), out inputBool))
        {
         Console.WriteLine("Please respond True or False"); 
        }
        //asignando las respuestas al array responses mediante lo que responda el usuario (true o false)
        responses[askingIndex]=inputBool;
        ++askingIndex;
      }
        
      
      //revisar la definición de la variable scoringIndex. Numeral 17
      int scoreindex = 0;
      int score = 0;
      bool inputresponses;
      foreach (var answer in answers)
        {  
        inputresponses = responses[scoreindex];
        Console.WriteLine("Input: " + inputresponses + "|" + "Answer: " +         (answers[scoreindex]));
        if (inputresponses == (answers[scoreindex]))
        {
          score++;
        }
        ++scoreindex;
        }
        Console.WriteLine($"You got {score} of {questions.Length}");
    }
  }
}