I am currently stuck on part a of this problem. I am having a problem with my stub, I am also running this on visual C++ 2008 express. My stub is a program i had to create to find the maximum value from the 10x20 array. For some reason that's not setting up right. I will post y errors the compiler gave me, but my compiler also don't least lines for whatever reason. so the errors may not make sense, but i'll point them out as carefully as possible.
okay the official problem states this:
A. Write a function named findmax() that finds and displays the maximum values
in a two dimensional array of integers. The array should be declared as a 10 row
by 20 column array of integers in main() and populated with random numbers
between 0 and 100.
B. Modify the function written above so that it also displays the row and column
numbers of the element with the maximum value.
Here's what I have so far:
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
int findMax(int[][20]);
int main()
{
const int j = 10;
const int k = 20;
int i,u;
int max;
int grade[j][k];
srand(time(NULL));
for(i=0;i<j;i++)
{
cout << endl;
for(u=0;u<k;u++)
{
grade[i][u]=rand()%100;
cout << setw(4) << grade[i][u];
}
}
findMax(grade);
cout <<"The max value is " << max;
system("pause");
return 0;
}
int findMax(int grade[][20])
{
int i, u;
int j = 10;
int k = 20;
int max = 0;
for(i=0;i<j; i++)
for(u=0; u<k; u++)
{ if (max < grade[i][u])
max = max+grade[i][u];
}
return max;
}
New Errors:
Run-Time Check Failure #3 - The variable 'max' is being used without being initialized.
So After the changes were made, the stub runs, but for some reason it isn't return my max to the int main. When I have it set to cout the maximum value it says the variable max wasn't initialized with a value.