my output for the main function is not outputting correctly. the first number is "2005398656" when all the numbers in the file are 1-7. the rest of the numbers fit in those parameters, but are out of order, and when I add the values in a row and output the sum the first 5 of 7 numbers are correct.
not to sure how to fix this, mainly the problem with the first number.
#include <iostream>
#include <fstream>
//Jacob Wilt
//Monkey Business
usingnamespace std;
ifstream infile;
ofstream outfile;
constint rowmax = 7; //the rows are each monkey
constint colmax = 7; //the columns are the days
void totalaverage(int []), least(int []), greatest(int []), monkeyaverage(), dayaverage();
int main()
{
infile.open("C:\\Users\\Jacob\\Desktop\\monkeyFile.txt");
outfile.open("monkeys.txt");
int sum[colmax];
int monkey[rowmax][colmax];
for (int i = 1; i <= rowmax; i++)
{
monkey[i][i] = 0;
}
int a = 0;
int b = 0;
int c = 0;
for (int i = 1; i <= 49; i++)
{
infile >> a >> b >> c;
monkey[a][b] = c;
cout << monkey[a][b] << " ";
if (i % 7 == 0)
cout << endl;
}
for (int i = 1; i <= rowmax; i++)
{
int x = 0;
for (int j = 1; j <= colmax; j++)
{
x = x + monkey[i][j];
}
sum[i] = x;
cout << sum[i] << " ";
}
totalaverage(sum);
least(sum);
greatest(sum);
monkeyaverage();
dayaverage();
infile.close();
outfile.close();
return 0;
}
void totalaverage(int sum[])
{
cout << "\n\nAVERAGE\n";
int total = 0;
int average;
for (int i = 1; i <= rowmax; i++)
{
total = total + sum[i];
}
average = total / rowmax;
cout << "Average = " << average;
}
void least(int sum[])
{
cout << "\n\nLEAST\n";
int small = 500;
for (int i = 1; i <= colmax; i++)
{
if (sum[i] < small)
{
small = sum[i];
}
}
cout << "Smallest = " << small;
}
void greatest(int sum[])
{
cout << "\n\nGREATEST\n";
int big = 0;
for (int i = 1; i <= colmax; i++)
{
if (sum[i] > big)
{
big = sum[i];
}
}
cout << "Largest = " << big;
}