Returning function array values average and highest/lowest

I am trying to create 2 functions, one that calculates and displays the average weekly food intake for 3 monkeys. (getAvg();)

Name Average weekly intake in pounds
Bonnie results
Clyde etc
Trigger etc

The other function will determine the monkey who ate the least amount of food in any one day and most amount.

Least amount: __monkeyname__ ate ___ pounds on Day #___
Most amount: ___monkeyname__ ate ___ pounds on Day #___

the test data that i read from the file food.txt is

45 33 55 66 77 88 100
88 77 66 55 44 33 22
44 55 00 66 77 88 99

I also can't figure out how to make the computer read in "00" to the array.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

const int MONKEYS = 3;
const int DAYS = 7;

void getMonkeys(ifstream &file, string M[]);
void getFood(ifstream &file, double a[][7]);
void print(string M[], double b[][7]);

double getAvg();
double getMinMax();

int main()
{
	double mFood[MONKEYS][DAYS];
	string mNames[MONKEYS];

	ifstream inFile;
	ifstream inFile2;

	inFile.open("names.txt");
	getMonkeys(inFile, mNames);
	inFile.close();

	inFile2.open("food.txt");
	getFood(inFile2, mFood);
	inFile2.close();
	
	print(mNames, mFood);

	system("pause");
	return 0;
}

void getMonkeys(ifstream &file, string M[])
{
	string name_holder;
	int c = 0;

	while (file >> name_holder)
	{
		M[c] = name_holder;
		c++; 
	}
}

void getFood(ifstream &file, double a[][7])
{
	double num_holder;
	int row = 0, col = 0, input = 0;

	while (file >> num_holder)
	{
		a[row][col] = num_holder;
		input++;
		col++;

		if (input%DAYS == 0)
		{
			row++;
			col=0;
		}
	}
}

void print(string M[], double b[][7])
{

	cout << "Name" << "\t" << "    " << "Day 1\t" << "Day 2\t" << "Day 3\t"
		<< "  " << "Day 4" << "  " << "Day 5" << "  " << "Day 6" << "  " << "Day 7" << endl;
	cout << "-----" << "\t" << "    " << "-----" << "\t" << "-----" << "\t" << "-----" << "  "
		<< "-----" << "  " << "-----" << "  " << "-----" << "  " << "-----" << endl;

	for(int c=0;c<MONKEYS;c++)
	{
		cout<<setw(14)<<left<<M[c];

		for(int i=0;i<DAYS;i++)
		{
			if(b[i][c]==0)
				cout<<"0";
			cout<< b[c][i] << "     ";
		}
		cout<<endl;
	}
	cout << endl;
	cout << endl;
}
Topic archived. No new replies allowed.