+ 1

C# Multiple options in welcome

I've been doing exercises today and am stuck on this one. When maybe is inputted it the response should be: "Keep practicing". What am I missing here? I've been staring at this for a while now. I appreciate the help. using System; class MainClass { public static void Main (string[] args) { Console.WriteLine("Do you like programming?"); var v1 = Console.ReadLine(); if (v1 == "yes") { Console.WriteLine("Good! Me too!"); if (v1 == "maybe") Console.WriteLine("Keep practicing!"); } if (v1 == "no") { Console.WriteLine("That's a shame. It's fun!"); }

21st Jul 2018, 4:55 PM
Alex
Alex - avatar
2 Respostas
0
move "maybe" out of "yes" condition. I also suggest you to use "else" and "equals". if(v1.Equals("yes")) { ... } else if(v1.Equals("maybe")) { ... }
21st Jul 2018, 7:51 PM
AtoMX
AtoMX - avatar
0
I would use a switch statement, instead of 'if' loops.
22nd Jul 2018, 5:02 AM
Bagshot
Bagshot - avatar