0

Hi there when I type yes or no/No it doesnt do what Its supposed to do what am I doing wrong?

enter image description here

class Program { static void Main(string[] args) { Console.WriteLine("Username:"); String user = Console.ReadLine(); Console.WriteLine("Password:"); String Pass = Console.ReadLine(); Console.WriteLine("Are You Sure Your User: " + user + " And Pass: " + Pass + " is correct? Yes/No"); Console.ReadLine(); if (Console.ReadLine() == "Yes" || Console.ReadLine() == "yes") { Console.WriteLine("You May now close this"); } else if(Console.ReadLine() == "No" || Console.ReadLine() == "no") { Console.WriteLine("Pleas Press enter"); System.Diagnostics.Process.Start(Environment.GetCommandLineArgs()[0], Environment.GetCommandLineArgs().Length > 1 ? string.Join(" ", Environment.GetCommandLineArgs().Skip(1)) : null); } } } 
3
  • 4
    You're calling ReadLine twice in each if statement. Call it once, assign the results to a string, then test that string. Commented Oct 5, 2018 at 23:00
  • Remember that each call to Console.ReadLine is executed even in if statement! Except for, of course short-circuting behaviour of || and && operators. Besides - you should provide more information - what it is supposed to be doing and what it is doing. Just "wrong" is not enough! Some info about short circuting: c-sharpcorner.com/article/short-circuit-evaluation-in-c-sharp Commented Oct 5, 2018 at 23:00
  • Alternatively you could use if(Console.ReadLine().ToLower() == "yes") Commented Oct 5, 2018 at 23:06

1 Answer 1

6

You are asking for user input twice. The first Console.ReadLine(); is what you are typing "Yes" or "No" into, however your if/else if statements are asking for input again.

Console.WriteLine("Are You Sure Your User: " + user + " And Pass: " + Pass + " is correct? Yes/No"); var input = Console.ReadLine(); if (input == "Yes" || input == "yes") { Console.WriteLine("You May now close this"); } else if(input == "No" || input == "no") { Console.WriteLine("Pleas Press enter"); System.Diagnostics.Process.Start(Environment.GetCommandLineArgs()[0], Environment.GetCommandLineArgs().Length > 1 ? string.Join(" ", Environment.GetCommandLineArgs().Skip(1)) : null); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.