170k views
2 votes
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 two-dimensional 3 × 5 array, where each row represents a different monkey and each column represents a 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: • 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.

1 Answer

1 vote

Answer:

#include<iostream>

using namespace std;

int main()

{

double data[3][5],avg,least,most,total;

int leastNum,mostNum;

for(int i=0;i<3;i++)

{

cout<<"Enter quantity of food for monkey "<<i+1<<":\\";

for(int j=0;j<5;j++)

{

cout<<"Day "<<j+1<<": ";

cin>>data[i][j];

}

}

least = data[0][0];

most = data[0][0];

for(int i = 0;i<3;i++)

{

for(int j = 0;j<5;j++)

{

total+=data[i][j];

if(data[i][j]>most)

{

most=data[i][j];

mostNum=i+1;

}

if(data[i][j]<least)

{

least=data[i][j];

leastNum=i+1;

}

}

}

avg=total/5.0;

cout<<"Average food eaten in a day by all the 3 monkeys: "<<avg<<endl;

cout<<"Most amount of food eaten in a day: "<<most<<" by monkey: "<<mostNum<<endl;

cout<<"Least amount of food eaten in a day: "<<least<<" by monkey: "<<leastNum<<endl;

return 0;

}

User Lcl
by
5.6k points