The "fillArray()" function has a parameter with the identifier "arrayData". Later within the function's compound statement, another array is declared with the same identifier. The compiler is unable to determine which array is being referred to when that identifier is used in your source code. The identifiers within your source code must be unique, or you will receive a compilation error.
The definition of the "fillArray()" function and the first for loop within the function's compound statement are both missing a curl bracket. These missing brackets would have been much easier to locate if you had used the code tags to format your source code.
EDIT: After rereading the source code, I discovered a few more problems that I have not yet mentioned above. I'm sure the creator of this thread is able to solve the remaining problems without help from another member.
/**
* FUNCTION #1 - 10 points
* This function should fill the 2D array with random numbers between 0 and 100
* The numbers must be different every time the program is run, so you need to
* research the best way to generate random numbers in this range.
*/
void fillArray(int arrayData[DIM][DIM]){
for (int i=0;i<DIM;i++){
for (int j=0;j<DIM;j++){
arrayData[i][j]=rand()%100;
}
}
}
/**
* FUNCTION #2 - 10 points
* Print the given array in matrix form with sufficient spacing between numbers
* so that the columns line up. The message should be printed at the top of the matrix.
* See the sample output at the top of this file.
*/
void printArray(string message, int arrayData[DIM][DIM]){
cout << message << endl;
for (int i=0;i<DIM;i++){
for (int j=0;j<DIM;j++){
cout << setw(5) << arrayData[i][j];
}
cout <<endl;
}
}
/**
* FUNCTION #3 - 10 points
* Write the given matrix to a file named by the fileName parameter. The file
* should be written in matrix format (only numbers - no other text or bars)
*/
void writeFile(string fileName, int arrayData[DIM][DIM]){
ofstream myfile;
myfile.open("arrayData.txt");
for (int i=0;i<DIM;i++){
for (int j=0;j<DIM;j++){
myfile << arrayData[i][j] << " ";
}
myfile << "\n";
}
}
/**
* FUNCTION #4 - 10 points
* Read the file named by the fileName parameter into the
* 2D array arrayData. You can assume that the file is formatted
* correctly and contains integers.
*/
void readFileIntoArray(string fileName, int arrayData[DIM][DIM]) {
ifstream myfile;
myfile.open("arrayData.txt");
for (int i=0;i<DIM;i++){
for (int j=0;j<DIM;j++){
myfile >> arrayData[i][j];
}
}
}
/**
* FUNCTION #5 - 10 points
* Transpose the input array, multiplying each value by the supplied multiplier
*/
void transposeAndMultiplyArray(int arrayData[DIM][DIM], int multiplier){
for (int i=0;i<DIM;i++){
for (int j=0;j<DIM;j++){
arrayData[i][j]= arrayData[i][j]*multiplier;
}
}
}
/**
* DO NOT MODIFY THIS CODE!
*/
int main()
{
int write_data[DIM][DIM];
fillArray(write_data);
printArray("Random array",write_data);
writeFile(DATAFILE,write_data);
int read_array[DIM][DIM];
readFileIntoArray(DATAFILE, read_array);
transposeAndMultiplyArray(read_array, 5);
printArray("Transposed and multiplied array", read_array);
system("pause");
return 0;
}