You are using a version without Ads of this website. Please, consider donating:

### 2-d Array and Functions

The question is...
Your program should ask the user for data to (partially) fill a 2-d array.
Ask them how many rows, how many columns, and then ask for the appropriate
number of values to fill the array.

You will then total each row in the array and determine which row has the
largest total and what that total is.

Then you will output the maximum and the row number the maximum occured in.
(The row number should be output in terms that a non-programmer would
understand -- if it's in the 1st row -- the one with subscript 0 -- output
it as row 1.)

This program has to be done using functions. This is what I have so far.

#include <iostream>
using namespace std;

const int MAXROWS = 100;
const int MAXCOLS = 100;

void GetData(int scores[][MAXCOLS], int RowsUsed, int ColsUsed);
void CalcMax(int scores[][MAXCOLS], int RowsUsed, int ColsUsed, int total, int Max, int rownum);
void PrintMax(int scores[][MAXCOLS], int Max, int rownum);

int main()
{
int RowsUsed;
int ColsUsed;
int total;
int Max;
int rownum;
int scores[MAXROWS][MAXCOLS];

GetData(scores, RowsUsed, ColsUsed);
CalcMax(scores, RowsUsed, ColsUsed, total, Max, rownum);
PrintMax(scores, Max, rownum);

return 0;
}

void GetData(int scores[][MAXCOLS], int RowsUsed, int ColsUsed)
{
cout << "How many rows would you like?" << endl;
cin >> RowsUsed;
cout << "How many columns would you like?" << endl;
cin >> ColsUsed;

for(int i = 0; i < RowsUsed; i++)
{
for(int j = 0; j < ColsUsed; j++)
{
cout << "Enter number for row " << i + 1 << " and column "
<< j + 1 << endl;
cin >> scores[i][j];
}
}
}
void CalcMax(int scores[][MAXCOLS], int RowsUsed, int ColsUsed, int total, int Max, int rownum)
{
for (int i = 0; i < RowsUsed; i++)
{
total = 0;
for (int j = 0; j < ColsUsed; j++)
{
total += scores[i][j];
}
if(total > Max)
{
Max = total;
rownum++;
}
}
}
void PrintMax(int scores[][MAXCOLS], int Max, int rownum)
{
cout << "A maximum of " << Max << " occurs at row " << rownum << endl;
scores[MAXROWS][MAXCOLS]++;
}

I am getting these errors and I don't know how to fix them.
program05.cpp: In function int main():
program05.cpp:33:39: warning: RowsUsed is used uninitialized in this function [-Wuninitialized]
program05.cpp:33:39: warning: ColsUsed is used uninitialized in this function [-Wuninitialized]
program05.cpp:34:59: warning: total is used uninitialized in this function [-Wuninitialized]
program05.cpp:34:59: warning: Max is used uninitialized in this function [-Wuninitialized]
program05.cpp:34:59: warning: rownum is used uninitialized in this function [-Wuninitialized]

You pass uninitialized variables as arguments to the functions.