#include <iostream>
#include <string>
usingnamespace std;
main ()
{
string subject1_name;
string subject2_name;
int subject1_age;
int subject2_age;
cout << "Please enter the first subject's name: " << "\n";
getline( cin, subject1_name, '\n' );
cout << "Please enter the second subject's name: " << "\n";
getline( cin, subject2_name, '\n' );
cout << "Now, please enter the first subject's age: " << endl;
cin subject1_age;
cout << "And then the second subject's age: " << endl;
cin subject2_age;
int subject1_overage = subject1_age - subject2_age;
int subject2_overage = subject2_age - subject1_age;
if ( subject1_age > subject2_age )
{
cout << subject1_name << " is oldest! " << subject1_overage << " years older, actually.\n";
}
elseif ( subject2_age > subject1_age )
{
cout << subject2_name << " is oldest! " << subject2_overage << " years older, actually.\n";
}
}
As you can see, it's a very simple program. It's purpose is to take 2 subjects names and ages, and then print out the name and age, and also tell how much one subject is older than another.
No. The compiler is telling you that it got confused on lines 18 and 20, so you should look at those lines for a syntax error. When the compiler encoutners a syntax error, it tries to recover by looking for the next token it recognizes, which is usually a ;.