Average, Highest Value and Lowest Value (2D Array)

Ok, so here it goes. I'm awful at C++. I can't seem to really grasp it on my own and have talked to a lot former C++ students in hopes that I will learn something but that has yet to happen... I understand math pretty well, can't say that about coding however. With that being said, can someone explain to me how to obtain the average per row and the total average? Also the highest amount and the lowest amount.

Directions are: Write a program that stores this information in a 2D 3 x 7 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:

1) Average amount of food eaten per day by the whole family of monkeys
2) the least amount of food eaten during the week by any one monkey
3) the greatest amount of food eaten during the week by any one monkey
*input validation: Do not accept neg numbers for pounds of food eaten
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
	const int ROW = 3, COL = 7;
	int Array[ROW][COL], Monkey[3]={0,0,0};
	int NumMon, NumDay;
	double totalAvg, averageM1, averageM2, averageM3; 
	double Sum = averageM1+averageM2+averageM3;
	double TotalAvg = Sum/7;
	double LeastAmt, HighAmt;

	for (NumMon=0; NumMon <= 2; NumMon++)
	{
		for (NumDay=0; NumDay <= 6; NumDay++)
		{
			cout << "Input amount of food consumed by monkey number " << NumMon+1 << " for day number " << NumDay+1 << "." <<endl;
			cin >> Array[NumMon][NumDay];

			while (Array[NumMon][NumDay] < 0)
				{
					cout << "Food consumed must be a positive number.\n";
					cin >> Array[NumMon][NumDay];
				}
			Sum += Array[NumMon][NumDay];
			Monkey[3] += Array[NumMon][NumDay]
		}
	}
	return 0;
}
how to obtain the average per row
Sum all values in single row and divide it by amount of columns
and the total average
Sum all values and divide it by amount of rows × amount of columns
Also the highest amount and the lowest amount.
Store first value in a row in current highest/lowest variable. Then iterate over other values in a row comparing them with your current variable and replacing it if value is larger/lower than stored.
Last edited on
Topic archived. No new replies allowed.