0

[SOLVED] (thank you) Yes or no

Hey. I’m trying to write a method that asks a question of yes or no, takes an input of yes or no, and outputs yes, no, or error depending on your input. My current effort is throwing up an error telling me yes and no don’t exist, in the current context or some such. Could anyone take a look and point me in the right direction please? https://code.sololearn.com/c7mE2M13lBpY/?ref=app /edit I got rid of the doesn’t exist messages, but now it’s outputting both my answer and the else clause. Suggestions?

21st May 2021, 2:59 PM
Andrew Hall
Andrew Hall - avatar
5 ответов
+ 2
You are using if twice
21st May 2021, 3:09 PM
Atul [Inactive]
+ 2
Use else if . Your 2nd if condition is working for else. Not for first if
21st May 2021, 3:10 PM
Atul [Inactive]
+ 2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { Console.WriteLine("type yes, or no"); string answer = Console.ReadLine(); if (answer == "yes") { Console.WriteLine("yes"); } else if (answer == "no") { Console.WriteLine("no"); } else { Console.WriteLine("Error"); } } } }
21st May 2021, 3:10 PM
Atul [Inactive]
+ 2
Andrew Hall my pleasure
21st May 2021, 3:18 PM
Atul [Inactive]
0
Cheers Atul. So simple, but much appreciated 👍
21st May 2021, 3:14 PM
Andrew Hall
Andrew Hall - avatar