fork download
  1. //Nathan Dominguez CSC5 Chapter 7, P. 444, #4
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * Compute Pounds of Bananas Eaten in a Week by Monkeys
  6.  * _____________________________________________________________________________
  7.  * This program will store how many pounds of food each of its three monkeys
  8.  * eats each day during a typical week. It will then calculate the average
  9.  * number of bananas eaten per day. The program will also display the least
  10.  * and most amounts eaten in a week.
  11.  * _____________________________________________________________________________
  12. * INPUT
  13.  * poundsEaten[][] : The number of pounds eaten per monkey per day
  14.  *
  15.  * OUTPUT
  16.  * highest : The highest number of pounds eaten
  17.  * lowest : The lowest number of pounds eaten
  18.  * total : The total number of pounds eaten
  19.  * average : The average number of pounds eaten
  20.  *
  21.  ******************************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25.  
  26. int main()
  27. {
  28. int poundsEaten[3][7]; //array size
  29. // per monkey/day
  30. int highest = 0; // OUTPUT - The most # of lbs eaten by any monkey
  31. int lowest = 0; // OUTPUT - The lowest # of lbs eaten by any monkey
  32. int total = 0; // OUTPUT - The total # of lbs eaten by all monkeys
  33. float average; // OUTPUT - The average # of lbs eaten for all monkeys
  34.  
  35. //loop program for 3 monkeys for 7 days each
  36. for(int monkey = 0; monkey < 3; monkey++){
  37. for(int day = 0; day < 7; day++){
  38. cout << "Monkey " << monkey + 1;
  39. cout << ", Day " << day + 1 << ": ";
  40. cin >> poundsEaten[monkey][day];
  41. cout << endl;
  42.  
  43. //Accumulate the Total Pounds Eaten
  44. total += poundsEaten[monkey][day];
  45. }
  46. cout << endl;
  47. }
  48.  
  49. //declare Lowest and Highest
  50. lowest = poundsEaten[0][0];
  51. highest = poundsEaten[0][0];
  52.  
  53. //nested loop to compare each monkey
  54. for(int monkey = 0; monkey < 3; monkey++)
  55. {
  56. for(int day = 0; day < 5; day++)
  57. {
  58. if(poundsEaten[monkey][day] < lowest)
  59. {
  60. lowest = poundsEaten[monkey][day];
  61. }
  62. if(poundsEaten[monkey][day] > highest)
  63. {
  64. highest = poundsEaten[monkey][day];
  65. }
  66.  
  67. }
  68.  
  69. }
  70.  
  71. //compute Average Pounds Eaten
  72. average = total/15.0;
  73.  
  74. //output Results
  75. cout << "The daily average is: " << average << endl;
  76. cout << "The least amount eaten: " << lowest << endl;
  77. cout << "The most amount eaten: " << highest << endl;
  78.  
  79. return 0;
  80. }
Success #stdin #stdout 0.01s 5304KB
stdin
2 2 2 2 2 2 2 2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
stdout
Monkey 1, Day 1: 
Monkey 1, Day 2: 
Monkey 1, Day 3: 
Monkey 1, Day 4: 
Monkey 1, Day 5: 
Monkey 1, Day 6: 
Monkey 1, Day 7: 

Monkey 2, Day 1: 
Monkey 2, Day 2: 
Monkey 2, Day 3: 
Monkey 2, Day 4: 
Monkey 2, Day 5: 
Monkey 2, Day 6: 
Monkey 2, Day 7: 

Monkey 3, Day 1: 
Monkey 3, Day 2: 
Monkey 3, Day 3: 
Monkey 3, Day 4: 
Monkey 3, Day 5: 
Monkey 3, Day 6: 
Monkey 3, Day 7: 

The daily average is: 2.93333
The least amount eaten: 2
The most amount eaten: 3