lundi 21 septembre 2020

Why output does not show initialized value -1?

int main()
{
    cout << "Please enter your first name and age\n";
    string first_name = "???"; 
    int age = -1;               
    cin >> first_name >> age; 
    cout << "Hello, " << first_name << " (age " << age << ")\n";    
}

According to the book Programming Principles and Practice Using C++ 2nd edition (Author: Bjarne Stroustrup), when I provide the input

22 Carlos

the expected output should be:

22(age -1)

But when I run it, I get:

22(age 0)

What is the cause?

Aucun commentaire:

Enregistrer un commentaire