fork download
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main() {
  6. string front;
  7. string back;
  8. string name;
  9. int number;
  10.  
  11. cout << "How many names will u enter ?\n";
  12. cin >> number;
  13.  
  14. cout << "Enter the names\n";
  15. cin >> name;
  16.  
  17. front = name;
  18. back = name ;
  19.  
  20. for (int i = 1 ; i < number ; i++)
  21. {
  22. cin >> name;
  23.  
  24.  
  25. if ( name < front)
  26. {
  27. front = name;
  28.  
  29. }
  30. else if ( name > back )
  31. {
  32. back = name;
  33.  
  34. }
  35.  
  36. }
  37.  
  38. cout << "front is " << front << endl;
  39. cout << "back is " << back << endl;
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
saliha
vannesa
hamzu
kenny
quari
stdout
How many names will u enter ?
Enter the names
front is hamzu
back is vannesa