and can someone tell me how and explain to sort the name that user input in alphabetically order then print the first name and last name in the order. i try search the google, but i can't understand it.
it say i have to use vector, and i try but have errors.
and i can't use getline(cin,names).could anyone tell me why?
Code:
#include<iostream>
#include<string>
using namespace std;
int main()
{
int people,i;
string names;
cout << "How many people?(1 to 10)?"<<endl;
cin >> people;
while(people < 1 || people > 10)
{
cout <<"Max size between (1 to 10)" <<endl;
cout <<"Please enter again :"<<endl;
cin>>people;
}
cout << "enter the first name:" <<endl;
cin >> names[i];
for (i=1;i < people;i++)
{
cout <<"enter next name:"<<endl;
cin >> names[i];
}
return 0;
getchar();
}
example the output:
How many people are there (1 to 10)? 50
Maximum size should be between 1 and 10.
Please re-enter the number of people: 60
Maximum size should be between 1 and 10.
Please re-enter the number of people: -12
Maximum size should be between 1 and 10.
Please re-enter the number of people: 5
Enter person 1's name: Julie
Enter the next person's name: Popo
Enter the next person's name: Helmi
Enter the next person's name: Henry
Enter the next person's name: Frodo
Frodo is at the head of the line.
Popo is at the end of the line.
thanks..

