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?
5 Answers
+ 2
You are using if twice
+ 2
Use else if . Your 2nd if condition is working for else. Not for first if
+ 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");
}
}
}
}
+ 2
Andrew Hall my pleasure
0
Cheers Atul. So simple, but much appreciated đ