#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
const int NUM_PERSONS = 10;
vector<string> names(NUM_PERSONS);
vector<int> ages(NUM_PERSONS);
for (int i = 0; i < names.size(); i++)
{
cout << "Enter name: ";
getline (cin, names[i]);
cout << "Age: ";
cin >> ages[i];
cin.get(); // get rid of newline left in the input buffer
// (otherwise the next getline would fail)
}
/* star assuming that element 0 is both the lowest and the highest
(after all, it is the only element checked so far, so it is both
the lowest and the highest). Then, compare the rest, starting
at element 1 */
int pos_youngest = 0, pos_oldest = 0;
for (int i = 1; i < ages.size(); i++)
{
if (ages[i] < ages[pos_youngest])
{
pos_youngest = i;
}
if (ages[i] > ages[pos_oldest])
{
pos_oldest = i;
}
}
// Now print them
cout << endl;
for (int i = 0; i < names.size(); i++)
{
cout << names[i] << " - " << ages[i]; // no newline yet...
if (i == pos_youngest)
{
cout << " (youngest)";
}
if (i == pos_oldest)
{
cout << " (oldest)";
}
cout << endl;
}
return 0;
}