3) (50 pts) Arrays: A local zoo wants to keep track of how many pounds of food e
ID: 3698865 • Letter: 3
Question
3) (50 pts) Arrays: A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a tw dimensio different day of the week. The program should first have the user input the data for each monkey Then it should create a report that includes the following information: nal 3 x 7 array, where each row represents a different monkey and each column represents a Average amount of food eaten per day by the whole family of monkeys .The least amount of food eaten during the week by any one monkey . The greatest amount of food eaten during the week by any one monkey Input Validation: Do not accept negative numbers for pounds of food eaten.Explanation / Answer
#include <iostream>
using namespace std;
int main() {
cout<<"Enter the details of the monkey ";
int ar[3][7];
int avg,sum=0;
for(int i=0;i<3;i++)
{
cout<<"Enter the details of the "<<(i+1)<<" monkey ";
for(int j=0;j<7;j++)
{ cin>>ar[i][j];
sum+= ar[i][j];
}
}
int least=ar[0][0];int greatest=ar[0][0];
for(int i=0;i<3;i++)
{
for(int j=0;j<7;j++)
{ if(ar[i][j]<least)
{least=ar[i][j];}
if(ar[i][j]>greatest)
{greatest=ar[i][j];}
}
}
cout<<"Average amount of food eaten per day by whole family of the dogs is "<<sum/7.0<<" ";
cout<<"Least amount of food eaten by any dog on any day "<<least<<" ";
cout<<"Greatest amount of food eaten by any dog on any day "<<greatest<<" ";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.