Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- /*
- Name: Marshal Walker
- Assignment #3: Some half-assed "program" for a "dating service".
- Notes: this is fucking shit.
- */
- int main()
- {
- const int SIZE=9001; //these arrays are >9000
- string tempName, arrayName[SIZE];
- double oldestVal, oldestAge=0, tempAge, arrayAge[SIZE];
- int ctr, max, avg=0;
- ofstream fout("dates.fil");
- for(ctr=0;ctr<SIZE;ctr++){
- cout << "Enter Name: ";
- cin >> tempName;
- if(cin.eof())break;
- while(cin.fail()){
- cin.clear();
- cin.ignore(80, '\n');
- cout << "Please enter a valid name!" << endl << "Enter Name: ";
- cin >> tempName;
- }
- cin.clear();
- cin.ignore(80, '\n');
- cout << "Enter Age: ";
- cin >> tempAge;
- if(cin.eof())break;
- while(cin.fail()||tempAge<18||tempAge>100){
- cin.clear();
- cin.ignore(80, '\n');
- cout << "Please enter an age between 18 and 100!" << endl << "Enter Age: ";
- cin >> tempAge;
- }
- cin.clear();
- cin.ignore(80, '\n');
- arrayName[ctr]=tempName;
- arrayAge[ctr]=tempAge;
- if(arrayAge[ctr]>oldestAge){
- oldestAge=arrayAge[ctr];
- oldestVal=ctr;
- }
- max=ctr;
- }
- for(ctr=0;ctr<=max;ctr++){
- cout << left << setw(10) << arrayName[ctr] << arrayAge[ctr];
- if(ctr==oldestVal){
- cout << " - Oldest!";
- }
- cout << endl;
- avg+=arrayAge[ctr];
- }
- cout << left << setw(10) << "Average" << (avg/(max+1))*1.0;
- cout << endl << "Program ended successfully!" << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement