Advertisement
CatmanIX

BallAssDick

Dec 12th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7. /*
  8. Name: Marshal Walker
  9. Assignment #3: Some half-assed "program" for a "dating service".
  10. Notes: this is fucking shit.
  11. */
  12.  
  13. int main()
  14. {
  15.     const int SIZE=9001; //these arrays are >9000
  16.     string tempName, arrayName[SIZE];
  17.     double oldestVal, oldestAge=0, tempAge, arrayAge[SIZE];
  18.     int ctr, max, avg=0;
  19.    
  20.    
  21.     ofstream fout("dates.fil");
  22.  
  23.     for(ctr=0;ctr<SIZE;ctr++){
  24.         cout << "Enter Name:   ";
  25.         cin >> tempName;
  26.         if(cin.eof())break;
  27.         while(cin.fail()){
  28.             cin.clear();
  29.             cin.ignore(80, '\n');
  30.             cout << "Please enter a valid name!" << endl << "Enter Name:   ";
  31.             cin >> tempName;
  32.         }
  33.         cin.clear();
  34.         cin.ignore(80, '\n');
  35.         cout << "Enter Age:   ";
  36.         cin >> tempAge;
  37.         if(cin.eof())break;
  38.         while(cin.fail()||tempAge<18||tempAge>100){
  39.             cin.clear();
  40.             cin.ignore(80, '\n');
  41.             cout << "Please enter an age between 18 and 100!" << endl << "Enter Age:   ";
  42.             cin >> tempAge;
  43.         }
  44.         cin.clear();
  45.         cin.ignore(80, '\n');
  46.         arrayName[ctr]=tempName;
  47.         arrayAge[ctr]=tempAge;
  48.         if(arrayAge[ctr]>oldestAge){
  49.             oldestAge=arrayAge[ctr];
  50.             oldestVal=ctr;
  51.         }
  52.         max=ctr;
  53.     }
  54.     for(ctr=0;ctr<=max;ctr++){
  55.         cout << left << setw(10) << arrayName[ctr] << arrayAge[ctr];
  56.         if(ctr==oldestVal){
  57.             cout << " - Oldest!";
  58.         }
  59.         cout << endl;
  60.         avg+=arrayAge[ctr];
  61.     }
  62.     cout << left << setw(10) << "Average"  << (avg/(max+1))*1.0;
  63.  
  64.  
  65.  
  66.    
  67.     cout << endl << "Program ended successfully!" << endl;
  68.     system("pause");  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement