Click here to Skip to main content
15,908,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I started c # few days ago and had this question


as u can see in order to say yes or no i have asked the user to say 1 or 2 to say yes or no but how can i make the different decisons occur when the user says yes or no rather than 1 or 2

What I have tried:

int answer;
Console.WriteLine("So, Do you agree?");
Console.WriteLine("Yes(Press 1) or No (Press 2)");
answer = int.Parse(Console.ReadLine());


if (answer == 1)
{
Console.WriteLine("Good");

}
else
{
Console.WriteLine("Dissapointing");
}
Posted
Updated 4-Jun-18 1:56am

Try:
string reply = "";
while (reply != "yes" && reply != "no")
    {
    Console.Write("So, do you agree? ");
    reply = Console.ReadLine().ToLower();
    }
 
Share this answer
 
Comments
NotAComputerScienceStudent 4-Jun-18 5:47am    
Havent reached this level yet but your answer seems correct
Yeah i figured it out
i used
C#


Console.WriteLine("Do You Agree?");
string choice = Console.ReadLine();

switch (choice)
{
case "yes":
Console.WriteLine("Good Job");
break;

default:
Console.WriteLine("Dissapointing");
break;
}
Through this if i said yes the guy replied good job but if i said anyhting else he replied dissapointing
Thx for help though
 
Share this answer
 
v2
Comments
Richard MacCutchan 4-Jun-18 8:18am    
That is correct behaviour. Maybe you need to work through some more tutorials. I recommend this free book: .NET Book Zero by Charles Petzold[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900