Hey guys I trying to compute averages by row and store them in an array so that I can later print the array holding the averages. However for some reason the program crashes after creating the initial 2 dimensional array. The compiler isn't showing any errors anyone see what's wrong? Any help would be great!
Code:
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
const int ROW = 3;
const int COL = 4;
const int LOW = 1;
const int UP = 50;
const int SIZE = 4;
void GenerateArray(int[][COL], int, int, int, int);
void GenerateAverages(int[][COL], float[], int, int, int);
void PrintArray(int[][COL], int, int);
void PrintAveArray(float[], int);
int main()
{
srand(time(NULL));
int table[ROW][COL] = {0};
float a_table[SIZE] = {0};
GenerateArray(table, ROW, COL, LOW, UP);
PrintArray(table, ROW, COL);
cout << "\n\n";
GenerateAverages(table, a_table, ROW, COL, SIZE);
PrintAveArray(a_table, SIZE);
cout << "\n\n";
}//END OF MAIN
void GenerateArray(int t[ ][COL], int row, int col, int lower_limit, int upper_limit){
for (int r = 0; r < row; r++)
for (int c = 0; c < col; c++)
t[r][c] = rand()%(upper_limit - lower_limit + 1) + lower_limit;
}
void PrintArray(int t[][COL], int row, int col){
for (int r = 0; r < row; r++){
for (int c = 0; c < col; c++)
cout << setw(5) << t[r][c];
cout << endl;
}
}
void PrintAveArray(float t[], int size){
for (int i = 0; i < size; i++)
cout << setw(5) << t[i];
cout << endl;
}
void GenerateAverages(int table[][COL], float a[], int r, int c, int size){
int total = 0;
int i = 0;
float average = 0;
for (c = 0; c < COL; c++){
total = 0;
average = 0;
for (r = 0; r < ROW; r++)
{
total = total + table[r][c];
average = (float)(total/ROW);
}
a[c] = average;
}
}