1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <iostream>
#include <fstream>
#define FILE_IN "heightweight.dat"
using namespace std;
void TallestandLightest(int[][2], int*, int*);
int main()
{
char exit;
cout << "This program finds the tallset female and lightest female from a";
cout << endl;
cout << "given data set.";
cout << endl;
cout << endl;
int countera, counterb, hwarray[18][2], height, weight;
char gender[18];
ifstream input;
input.open(FILE_IN, ios::in);
if (input.fail())
cout << "File did not open";
input.getline(gender, 18);
countera = 0;
while (input&&countera<18)
{
counterb = 0;
input >> hwarray[countera][counterb];
input >> hwarray[countera][counterb + 1];
cout << hwarray[countera][counterb] << " " << hwarray[countera][counterb + 1] << endl;
countera++;
}
input.close();
TallestandLightest(hwarray, &height, &weight);
cout << "The tallest female is " << height << " inches tall.";
cout << endl;
cout << "The lightest female is " << weight << " pounds.";
cout << endl;
cout << endl;
cout << "Press any key to exit the program. ";
cin >> exit;
}
void TallestandLightest(int hwarray[][2], int *h_ptr, int *w_ptr)
{
int counta, countb;
int tallest = hwarray[0][0];
int lightest = hwarray[0][1];
counta = 0;
countb = 0;
//LOOK HERE
for (counta = 0; counta < 18; counta++)
{
if (hwarray[counta][countb] > tallest)
{
tallest = hwarray[counta][countb];
*h_ptr = hwarray[counta][countb];
}
}
counta = 0;
countb = 1;
//LOOK HERE
for (counta = 0; counta < 18; ++counta)
{
if (hwarray[counta][countb] < lightest)
{
lightest = hwarray[counta][countb];
*w_ptr = hwarray[counta][countb];
}
}
}
|