Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need help detecting 2 if statements at the same time

Discussion in 'Scripting' started by masterbuilder335, May 21, 2022.

  1. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    Code (CSharp):
    1. using System;
    2.  
    3. namespace HelloWorld
    4. {
    5.     class MainClass
    6.     {
    7.         // Entry Point For Program
    8.         public static void Main(string[] args)
    9.         {
    10.             Console.WriteLine("Enter your name:");
    11.  
    12.             String Name = Console.ReadLine();
    13.  
    14.             Console.WriteLine($"Thank you, so your name is {Name}?:");
    15.             if (Console.ReadLine() == "Yes" || Console.ReadLine() == "yes")
    16.             {
    17.                 Console.WriteLine($"So I will be calling you {Name}");
    18.             }
    19.            
    20.             if(Console.ReadLine() == "No" || Console.ReadLine() == "no")
    21.             {
    22.                 Console.WriteLine("Then Enter your Name again:");
    23.                 String Name2 = Console.ReadLine();
    24.                 Console.WriteLine($"So your name this time is {Name}");
    25.             }
    26.         }
    27.     }
    28. }
    29.  
     
  2. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    So I want to be able to type in either Yes/yes or No/no but it only detects the Yes/yes first so i have to say yes and i can't say No/no
     
    Last edited: May 21, 2022
  3. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Store the result of Console.ReadLine() after asking to confirm the name in a variable. Then use that variable to compare to "Yes" and "No".