So I am pretty new to C++, and I was playing around with the code. I was writing an if-statement that would check if you had written "yes" or "no" and then give you different answers based on that.
The problem I am having is that when I write down "no" it gives me the same answer as if I had written "yes"; "nice".
I am working with the console (MSDOS) and not an API, again I am pretty new to C++ and programming overall and that is probably why I can't get it to work.
Here's the code:
string happy;
getline(cin, happy);
if(happy == "yes" || "Yes")
{
cout << "Nice" << endl;
}
else if(happy == "no" || "No")
{
cout << "Not nice" << endl;
}
else
{
cout << "Alright..." << endl;
}
I have done my best to find out the answer and see if there is something wrong in the code, but I can't seem to find anything. Would be happy if you could help me.
Aucun commentaire:
Enregistrer un commentaire