Question

C++ Write a program to keep track of the amount of food that one monkey eats...

C++

Write a program to keep track of the amount of food that one monkey eats in one day. The program should have an array of 24 elements and allow the user to input the amount of food in grams that the monkey eats every hour in a single day so values in a (0.00 to 100.00 range). Once all data has been entered then the program should list the hour that the monkey ate the most plus the average food per hour that the monkey consumed.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

int main ()
{
float food[24];
//Read input from user
for(int i=0;i<24;i++){
cin>>food[i];
}
//Find maximum and total
float mx = food[0],total=0;
for(int i=1;i<24;i++){
if(food[i]>mx){
mx = food[i];
}
total = total+food[i];
}
//find avg
float avg = total/24;

cout<<"Maximum food is "<<mx<<" Average food is "<<avg<<endl;
return 0;
}


#include <iostream>
using namespace std;

int main ()
{
float food[24];
//Read input from user
for(int i=0;i<24;i++){
cin>>food[i];
}
//Find maximum and total
float mx = food[0],total=0;
for(int i=1;i<24;i++){
if(food[i]>mx){
mx = food[i];
}
total = total+food[i];
}
//find avg
float avg = total/24;

cout<<"Maximum food is "<<mx<<" Average food is "<<avg<<endl;
return 0;
}


OUTPUT :

Add a comment
Know the answer?
Add Answer to:
C++ Write a program to keep track of the amount of food that one monkey eats...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT