jeudi 4 avril 2019

If-Else Statement has a "Code will not be executed" in the Else code line (Beginner ;w;) [duplicate]

This question already has an answer here:

I am making a simple conversation code.

The user talks to the console about their name, age, and then I want to make the console ask if the user wants to know their age. I want to do that as a first test in using If-Else statements.

However, the code never seems to run after the else statement, instead there is a sentence saying that the Else statement will not be executed.

(Also, I know that there are MANY questions about this, but I am only a beginner, and the rest of the questions include very complicated code that I don't understand, thus I can't solve this despite reading lots of questions.)

Any idea why, and how I can solve this problem?

Thank you.

#include <iostream>
using namespace std;

int main() {

    string input;
    double name, age;

    cout<< "Hello! What is your name?";
    cin>> name;
    cout<< "That is a nice name," << name;

    cout<< "How old are you?";
    cin>> age;
    cout<< "Wow! Want to know my age?";
    cin>> input;



     if (input == "Yes" or "yes") {
         cout<< "Okay! I am 12 years old."; 

     } else {
         cout<< "Aww, okay.."; //Code is not executed here. ;w;
     }


    return 0;
}


Aucun commentaire:

Enregistrer un commentaire