+ 3

I have no idea what's wrong with this

My code isn't working for some reason, it prints both "you're stinky" and "you're cool" no matter the input, Idk man i just started and maybe i made a stupid mistake, this is C# by the way Console.Write("Name:"); var name = Console.ReadLine(); if (name == "nico") ; { Console.WriteLine("you're cool"); }; if (name != "nico") ; { Console.Writeline("You're stinky."); };

20th Nov 2020, 10:05 PM
Fujimori
Fujimori - avatar
4 Answers
+ 2
Hi there. You've used semicolons to terminate your If statements. That runs them but will cause no effect to the output since they have no body. After they're terminated, you're getting both outputs as simple print functions. Remove the semicolons and try re-running the code :)
20th Nov 2020, 11:13 PM
#Code
#Code - avatar
+ 2
Console.Write("Name:"); // use string instead of var string name = Console.ReadLine(); // Remove ; after if, and the closing bracket '}' if (name == "nico") { Console.WriteLine("you're cool"); } if (name != "nico") { // WriteLine not Writeline // Also practice proper identation for // readability. Console.WriteLine("You're stinky."); } You don't have to place ; in brackets, of if/else/else if and loops, only on statements. This should work
21st Nov 2020, 2:17 AM
かんでん
かんでん - avatar
0
I also tried using the name.contains thing but that didn't work either
20th Nov 2020, 10:06 PM
Fujimori
Fujimori - avatar
0
Ű§Ù„Ùˆ
22nd Nov 2020, 10:54 AM
ŰźŰ§Ù„ŰŻ ŰłÙŠŰŻŰčلي
ŰźŰ§Ù„ŰŻ ŰłÙŠŰŻŰčلي - avatar