#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int firstage; // an integer for storing first user's age
int secondage; // an integer for storing second user's age
string firstname; // a string for storing first user's name
string secondname; // a string for storing second user's name
cout<<"Input first user's name"<<endl; // ask for first user's name
getline( cin, firstname ); // and store the name as first
cout<<"Input second user's name."<<endl; // ask for second user's name
getline(cin, secondname); // and store the name as second
cout<<"Input "<<firstname<<"'s age"<<endl; // ask for first user's age
cin>>firstage; // and store the age as first.age
cout<<"Input "<<secondname<<"'s age"<<endl; // ask for second user's age
cin>>secondage; // and store the age as second.age
// compare first user's age and second user's age
if (firstage<secondage){cout<<secondname<<" older than "<<firstname;}
elseif (firstage==secondage) {cout<<firstname<<"'s and "<<secondname<<"'s age are same.";}
else {cout<<firstname<<" older than "<<secondname<<endl;}
system("pause");
}
2.Solution with structures (Thanks for Vlad From Moscow):
Also take into account that blank lines in the code are very important for its formatting and reading.
For example instead of
1 2 3 4 5 6
int x; // an integer for storing first user's age
int y; // an integer for storing second user's age
string first; // a string for storing first user's name
string second; // a string for storing second user's name
cout<<"Input first user's name"<<endl; // ask for first user's name
getline( cin, first );
it would be much better to write at least
1 2 3 4 5 6 7
int x; // an integer for storing first user's age
int y; // an integer for storing second user's age
string first; // a string for storing first user's name
string second; // a string for storing second user's name
cout<<"Input first user's name"<<endl; // ask for first user's name
getline( cin, first );
I still dont know structure and i am still a beginner so i am sharing the codes which i can understand. But if you share all the code using structure i can it as second solution