+ 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."); };
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 :)
+ 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
0
I also tried using the name.contains thing but that didn't work either
0
ۧÙÙ