the error in the code is the plus (+) sign is unrecognized as an identifier
the plus(+) operator is a operator but you aren't using it in the correct context
to fix it delete the multidimensional array declaration because its not needed
next delete:
multi_array[i][j] = i + point + j ; // assigns value to the array
now replace:
cout <<multi_array[i][j] <<endl; //displays array
with:
cout << "[" << i << "," << j << "] "; //displays array
and because you want it to look like a matrix in the output move the endl to the end of the SECOND for statement
so you code should look like this:
/* program: multi dimensional array
* description: creates a multi dimensional array, whose size the user inputs
*/
#include <iostream>
#include <string>
using namespace std;
int main(){
int first_dimension; //legnth of first dimension
int second_dimension; //length of second dimension
//iterating variables
int i;
int j;
//decimal point
string point = ".";
cout <<"What size do you want the first dimension to be." <<endl;
cin >>first_dimension; //input length of first dimension
cout <<"What size do you want the second dimension to be." <<endl;
cin >>second_dimension; //inputs length of second dimension
cout <<"---------------------------------------" <<endl;
//nested for loops to iterate through the array
for(i = 0; i < first_dimension; i++){
for(j = 0; j < second_dimension; j++){
cout << "[" << i << "," << j << "] "; //displays array
}
cout << endl;
}
return 0;
}
Geo121
|