+ 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!"); }
2 Respuestas
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")) {
...
}
0
I would use a switch statement, instead of 'if' loops.