1

One of the first Stroustrup exemples in his book Principles and practices using C++ reads as follows:

// read name and age (2nd version)
int main()
{
          cout << "Please enter your first name and age\n";
          string first_name = "???";      // string variable
                                                            // ("???” means “don’t know the name”)
          int age = –1;         // integer variable (–1 means “don’t know the age”)
          cin >> first_name >> age;      // read a string followed by an integer
          cout << "Hello, " << first_name << " (age " << age << ")\n";
}

The book says that by typing 22 Carlos I would get as output Hello, 22 (age -1), but, independent of initial value I always get a zero.

ps: Aside from this the program works as intended.

0 Answers0