hey folks! i have this simple code Console.Write("Are you Cool?"); string str = Console.ReadLine(); if (str == "yes") { Console.WriteLine("HAHA! THAT'S NOT TRUE!"); } if (str == "no"){ Console.WriteLine("no? weeell.....i think you are"); } if (str != "yes" || "no") { Console.WriteLine("I'm Sorry, I Didn't understand you...doofus"); } how do i make this work? it says it does not work with || since bool values cannot have bool operands Could anyone help me with this? any help is really appreciated :D
2/2/2017 9:42:36 AM
Kenneth Bore Eilertsen9 Answers
New AnswerBecause you are asking if both are true, if string is not "yes", and it is not "no" then print something
What @Filip said. Also you could do if, if else, else: Pseudo code: if(yes) ...HAHA else if(no) ...no? else ...doofus
string str = Console.ReadLine().ToLower(); str is now all lower case so you only need to check with "yes" and "no".
Thanks! that worked! may i ask for an explanation of why AND works but not OR?
is there also an easy way to make the code non-case sensetive? so that you can write ex: "YES", "Yes" or "yes"?
All the things i asked about works now :D Filips "if(str != "yes" && str != "no")" gloriously solved my problem! Jafcas "string str = Console.ReadLine().ToLower();" made my code cooler! Thanks a bunch!
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message