Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdlib>
- int main(){
- using namespace std;
- string name[10];
- int people;
- string min, max;
- cout << "How many people are there (1 to 10)? "<<endl;
- cin >> people;
- while(people<1 || people>10){
- cout<<"Maximum size should be between 1 and 10."<<endl;
- cout<<"Please re-enter the number of people:"<<endl; cin>>people;
- }
- cout<<"Enter person 1's name :"<<endl;
- cin>>name[0];
- for(int i=0; i<people-1; i++){
- cout << "Enter the next person's name"<<endl;
- cin >> name[i+1];
- if(i == 0){
- if(name[i].compare(name[i+1]) > 0){
- max = name[i];
- min = name[i+1];
- }
- else if(name[i].compare(name[i+1]) < 0){
- max = name[i+1];
- min = name[i];
- }
- }
- else{
- if(name[i+1].compare(max) > 0){
- max = name[i+1];
- }
- else if(name[i+1].compare(min) < 0){
- min = name[i+1];
- }
- }
- }
- cout << min << " is at the head of the line" << endl;
- cout << max << " is at the end of the line" << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment