LibsRwimps
Joined: 24 Mar 2006 Posts: 5
|
Posted: Thu Apr 14, 2005 3:18 am Post subject: how to populate 2d array with user entered values in c++? |
|
|
| hi, i'm starting out with c++ and have been writing a for-the-hell-of-it piece of code to calculate the product of two matrices. It runs but produced the wrong results. After hours of headaches I narrowed down the problem to the following code: cout<<"enter the elements of matrix A from left to right, top to bottom >";for (a=0; a>mat1[a][b]; }}where y1 and x1 are the height and width of matrix "mat1" respectively. The problem is that the numbers I enter get mixed up and the numbers that get put into the array are different. example: If I declare the array mat1 to be of size x1=2 and y1=2, and input the numbers 1, 2, 3, 4 then when I display the array contents afterwards with cout, it turns out to be 1, 3, 3, 4.If I enter the numbers 1,2,3,4,5,6,7,8,9 into a 3x3 array then it turns out to be 9 4 7 4 7 8 7 8 9any help? |
|