Thursday, August 15, 2013

Student Line Up


#include <iostream>
#include <string>
using namespace std;

int main()
{
 string name;
 string firstPerson;
 string lastPerson;
 int students;


 do
 {
  cout << "Enter the number of people in the class: ";
  cin >> students;
  //cin.ignore();

  if (students < 1 || students > 25)
   cout << "Please re-enter the number of people, must be greater than 1 or less than or equal to 25.\n\n";
  
 }
 while (students < 1 || students > 25);

 /* cout << "Please re-enter the number of people, must be greater than 1 or less than or equal to 25.\n\n";
  cout << "Enter the number of people in the class: "<<endl;
     cin >> students;
  cin.ignore();*/

  /* cout << "Please enter the names:"<<endl;
  cin.clear();
  cin.ignore(2);
  getline(cin,name);
  firstPerson=name;*/

 cin.clear();
 cin.ignore(1,'\n');

 for (int x = 0 ; x < students ; x++)
 {
  cout << "Please enter the "<< x+1 << " name:" << endl;
  /*cin.clear();
  cin.ignore(1,'\n');*/
  getline(cin,name);


  if(x == 0)
  {
   firstPerson=name;
   lastPerson = name;
  }
  /*cout << " Please enter the " << x+2 << " name: ";
  cin.clear();
  cin.ignore(2);
  getline(cin,name);*/

      if(firstPerson>name)
   {
    firstPerson=name;
 
   }

   if  (lastPerson<name)
 
   {
     lastPerson=name;
   }

 }


 cout << "the first person in the list is:"<<firstPerson<<'\n';
    cout<< "the last person in the list is:"<<lastPerson<< endl;
 
 system("pause");
 return 0;
}

No comments:

Post a Comment