My code always outputs to true | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

My code always outputs to true

So I am experimenting with objects and classes by making a program that makes a "person", but I stopped to test and make sure my if/else was working and noticed it always outputted to true. Am I doing something wrong or does solo learn just not like if/else statements (I have just started using this and it is a browser compiler so I"m not sure) https://code.sololearn.com/csv7EJxUe83Q/#cpp EDIT: thanks to visph for the answer! (I don't know how to reply to comments :/)

31st Jan 2017, 6:24 PM
roflcow2
2 Answers
+ 3
At least, you have one mistake at line: if(input == "yes" || "y"){ Doing as is, result as always true, because "y" is always true ^^ You do correct by this way: if((input == "yes") || (input=="y")){
31st Jan 2017, 5:49 PM
visph
visph - avatar
+ 1
@rocflcow2: I see your edit XD I guess you'll quickly find... it's no more hard than posting a question ;) ... or upvote :P
31st Jan 2017, 8:21 PM
visph
visph - avatar