| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Basic 2D Array Assignment Help
My assignment asks to input a file Matrix.dat which contains a column of values.
ex. Matrix.dat: 3 4 1 2 3 4 5 6 7 8 9 10 11 12 The first value is set to the rows and the second to columns. The rest are inputted into the array a la: 1 2 3 4 5 6 7 8 ... etc. I've gotten this far and im now stuck :x #include <cmath> #include <iostream> #include <fstream> #include <iomanip> using namespace std; int main() { float Data, Min, Max, MM; int M, N, I, J; ifstream File; File.open("Matrix.dat"); File >> M; File >> N; float Matrix[M][N]; File >> Matrix[M][N]; if(M < 1 || M > 15) { cout << "Error: Row must be greater than 1 and less than 15." << endl; return 0; } else if(N < 1 || N > 15) { cout << "Error: Row must be greater than 1 and less than 15." << endl; return 0; } else{ for(I=0; I<=M-1; I++){ for(J=0; J<=N-1; J++){ cout << Matrix[I][J]; } cout << endl; } } return 0; } (compiled in g++) After the array has been filled, i also have to normalize it, but that is simple enough once i get the array working. thanks for your time |
|
#2
|
|||
|
|||
|
Please post your code using the code tags provided to maintain formatting and make it easier to read.
It helps a lot if you can tell us what your code already does and where you are stuck. Do you have compilation errors, runtime errors or just a problem understanding part of it? -KM- |
|
#3
|
|||
|
|||
|
matrix
Instead of
"File >> Matrix[M][N];" I have used for(I=0; I<=M-1; I++){ for(J=0; J<=N-1; J++){ File >> Matrix[I][J]; } } Each matrix component takes then the right value. ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Basic 2D Array Assignment Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|