Need help fit if- statement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

25th Nov 2017, 2:58 PM
Jan Janser
Jan Janser - avatar
2 Answers
+ 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.
25th Nov 2017, 3:09 PM
Mustafa K.
Mustafa K. - avatar
+ 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?")
25th Nov 2017, 3:35 PM
Jan Janser
Jan Janser - avatar