A local zoo wants to keep track of how many pounds of food each animal eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 × 4 array, where each row represents a different animal and each column represents a different day of the week. The program should first have the user input the species and then the data for each animal. Then it should create a report that includes the following information:
Input Validation: Do not accept negative numbers for pounds of food eaten.
Create a function:
• Get food eaten
• 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:
Expected Output
Check each Mimir test case for expect output
#include <iostream>
using namespace std;
int main()
{//declaration of 2darray
int arr[4][10];
float avg[10];
//reading input from user
for(int i=0;i<3;i++)
{ cout<<"enter the data for monkey"<<i<<" :";
for(int j=0;j<7;j++)
{
cin>>arr[i][j];
if(arr[i][j]<0)
{
cout<<"enter postive numbers for pounds of food eaten";
return 0;
}
}
}
//caluclating average
for(int j=0;j<7;j++)
{
avg[j]=float(arr[0][j]+arr[1][j]+arr[2][j])/3;
}
//calucating largest and smallest amount of food eaten by monkeyes
int largest=arr[0][0];
int smallest=arr[0][0];
for(int i=0;i<3;i++)
{
for(int j=0;j<7;j++)
{
if(largest<arr[i][j])
{
largest=arr[i][j];
//column location of largest element
}
if(smallest>arr[i][j])
{
smallest=arr[i][j];
//column location of smallest element
}
}
}
cout<<"_________________Report__________________"<<endl;
cout<<"Average food eaten by monkeys:"<<endl ;
for(int j=0;j<7;j++)
{
cout<<"Day "<<j+1<<":" <<avg[j]<<endl;
}
cout<<"The least amount of food eaten by monkeys :"<<smallest<<endl;
cout<<"The greatest amount of food eaten by monkeys :"<<largest;
}
Comments
Leave a comment