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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#include<iostream>
using namespace std;
const int DAYS = 7;
void inputArray(float food[][DAYS],int tigers);
void AvgTig(float food[][DAYS], float tavg[], int tigers);
float Most(float food[][DAYS], int , float);
float least(float food[][DAYS], int , float);
int main()
{
float maximum = 0;
float minimum = 0;
float total = 0.0f;
float totaverage = 0.0f;
float result = 0;
const int TIGERS = 3;
float food[TIGERS][DAYS];
int temp, amb;
inputArray(food,TIGERS);
maximum = food[0][0];
minimum = food[0][0];
float tavg[TIGERS];
AvgTig(food, tavg, TIGERS);
cout << "\n \n \n";
cout << "Average for Tiger 1, 2 & 3 in Order: \n";
for (int i = 0; i < TIGERS; ++i) {
cout << tavg[i] << " ";
}
cout << "\n \n ";
cout << "Enter whether you want to find minimum for tiger 1 2 or 3. (Please only enter 0, 1 or 2): ";
cin >> temp;
least(food, temp, minimum);
cout << "\n";
cout << "The Tiger " << temp << " has minimum: " << minimum << " ";
cout << "\n \n ";
cout << "Enter which tiger you want to find maximum for: ";
cin >> amb;
Most(food, amb, maximum);
cout << "The Tiger " << amb << " has maximum: " << maximum << " ";
system("PAUSE");
return 0;
}
void inputArray(float food[][DAYS],int tigers) {
int total = 0;
for (int tig = 0; tig < tigers; tig++)
{
for (int day = 0; day < DAYS; day++)
{
cout << "TIGER " << (tig + 1) << ", day " << (day + 1) << ": ";
cin >> food[tig][day];
}
cout << endl;
}
}
void AvgTig(float food[][DAYS], float tavg[], int tigers)
{
for (int i = 0; i < tigers; i++)
{
float total = 0;
for (int day = 0; day < DAYS; day++)
{
total += food[i][day];
}
// I have it for the tiger i, so save it
tavg[i] = total / DAYS;
cout << endl;
}
}
float least(float food[][DAYS], int temp, float min) //loop for days only
{
min = food[0][0]; //temp has to be les
for (int j = 0; j < DAYS; ++j) {
if (food[temp][j] < min)
min = food[temp][j];
}
return min;
}
float Most(float food[][DAYS], int amb, float max) //loop for days only
{
max = food[0][0];
//amb has to be less than 3
for (int j = 0; j < DAYS; ++j) {
if (food[amb][j] > max)
max = food[amb][j];
}
return max;
}
|