If someone could help me figure out why this error is happening I would be very very happy. I feel like my code should compile yet I am getting this error with both of my void functions.
Here is my code...
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
// global constant variables
const int YEARS = 8;
const int MONTHS = 12;
const int SPACER =5;
// function prototypes
// function to read in values
void getData(double[][MONTHS], int[]);
// function to display values in table format
void printData(double[][MONTHS], int[]);
// function to print data to screen in table format using arrays
int main()
{
double rain [YEARS][MONTHS];
int years[YEARS];
getData(rain, years);
printData(rain, years);
return 0;
}
// function definitions
void getData (double rainArray[][YEARS], int yearArray[])
{
ifstream fin;
fin.open("rainfall.txt");
if (!fin)
{
cout << "Error opening file, shutting down now.\n" ;
exit(EXIT_FAILURE);
}
else
{
for( int i = 0; i < YEARS; i++)
{
fin >> yearArray[i];
for (int j = 0; j < MONTHS; j++)
{
fin >> rainArray[i][j];
}
}
}
fin.close();
}
void printData (double rainArray[][YEARS], int yearArray[])
{
for ( int i = 0; i < YEARS; i++){
cout << yearArray[i] << setw(SPACER);
for ( int j = 0; j < MONTHS; j ++)
cout << rainArray[i][j] << setw(SPACER);
}
cout << endl;
}
You have dimension mismatch in your genData
parameter and rain
array:
You have:
double rain [YEARS][MONTHS];
but used it in a wrong way:
void getData (double rainArray[][YEARS], int yearArray[])
//^^^ should be rainArray[YEARS][MONTHS]
similar issue for the printData
function