+ 1
Need help fit if- statement
Hab someone say how do i get the if-statement after a Console.ReadLine command Not with Numbers but words Example that the Programm ask "Is Today a good day?" ans you respond with "yes" or "no". I want then use if for yes, no and else how do i do that. sorry for the stupid question i started Learning yesterday.
2 Réponses
+ 2
I couldn't understand your question exactly.
string respond; // you need to declare string variable
Console.WriteLine("Is today a good day? "); //programm asks today is good or not
Console.ReadLine(respond); //user is going to enter something (yes or no)
if(respond == "yes") //checking respond
Console.WriteLine("Perfect"); //today is good so programm says perfect.
else
Console.WriteLine("Why? "); //today is not good so asks why is your today bad?
There are not too much codes in if statement so we did not put curly brackets.
+ 1
I write that Code simular to your answer just instead of "respond" i write "answer" as string but at the line
Console.ReadLine(answer); is a error
my code
string answer;
Console.WritLine("Hello is today a good day?");
Console.ReadLine(answer);
if (answer == "yes")
Console.WritLine("Good");
if (answer == "no")
Console.WritLine("Oh too bad")
else
Console.WritLine("Come again?")