This is the code I have so far. I only need help with displaying it as a chart and finding the average. Please ^.^
Expand|Select|Wrap|Line Numbers
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- void getFood(double arrayPound[3][7]);
- void displayFood(double arrayPound[3][7]);
- void sortLeast(double arrayPound[3][7]);
- void sortGreatest(double arrayPound[3][7]);
- void sortAverage(double arrayPound[3][7]);
- int main(int argc, char *argv[])
- {
- double arrayPound[3][7];
- getFood(arrayPound);
- cout << endl;
- displayFood(arrayPound);
- cout << endl;
- sortAverage(arrayPound)
- cout << endl;
- sortLeast(arrayPound);
- sortGreatest(arrayPound);
- system("PAUSE");
- return EXIT_SUCCESS;
- }
- void getFood(double arrayPound[3][7])
- {
- double pound = 0;
- cout << "Food for the monkeys." << endl;
- cout << endl;
- for(int i = 1; i < 4; i++)
- {
- for(int u = 1; u < 8; u++)
- {
- cout << "Please enter the amount feed to monkey " << i << " on day " << u << " :";
- cin >> pound;
- while((cin == 0) || (pound < 0))
- {
- cin.clear();
- cin.ignore(10000, '\n');
- cout << "Please enter the amount feed to the monkey: ";
- cin >> pound;
- }
- arrayPound[i][u] = pound;
- }
- }
- }
- void displayFood(double arrayPound[3][7])
- {
- double pound;
- cout << "Total food eaten across all 7 days." << endl;
- cout << endl;
- for(int i = 1; i < 4; i++)
- {
- for(int u = 1; u < 8; u++)
- {
- cout << "The amount eaten by monkey " << i << " on day number " << u << " was: " << arrayPound[i][u] << endl;
- }
- }
- }
- void sortLeast(double arrayPound[3][7])
- {
- double leastVal = arrayPound[0][0];
- for(int i = 1; i < 4; i++)
- {
- for(int u = 1; u < 8; u++)
- {
- if(arrayPound[i][u] < leastVal)
- {
- leastVal = arrayPound[i][u];
- }
- }
- }
- cout << "The least amount was eaten: " << leastVal << endl;
- }
- void sortGreatest(double arrayPound[3][7])
- {
- double greatestVal = arrayPound[0][0];
- for(int i = 1; i < 4; i++)
- {
- for(int u = 1; u < 8; u++)
- {
- if(arrayPound[i][u] > greatestVal)
- {
- greatestVal = arrayPound[i][u];
- }
- }
- }
- cout << "The greatest amount was eaten: " << greatestVal << endl;
- }
- void sortAverage(double arrayPound[3][7])
- {
- double dailyAvg;
- for(int u = 1; u < 8; u++)
- {
- ( arrayPound[1][u] + arrayPound[2][u] + arrayPound[3][u] ) / 3 = dailyAvg;
- }
- cout << "The average eaten by the monkeys on day " << u << " was: " << dailyAvg << endl;
- }