gregorygarver.com Forum Index gregorygarver.com
San Francisco Real Estate Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to populate 2d array with user entered values in c++?

 
Post new topic   Reply to topic    gregorygarver.com Forum Index -> Content Writing
Author Message
LibsRwimps



Joined: 24 Mar 2006
Posts: 5

PostPosted: Thu Apr 14, 2005 3:18 am    Post subject: how to populate 2d array with user entered values in c++? Reply with quote

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?
Back to top
Fran



Joined: 07 Mar 2007
Posts: 4

PostPosted: Sun May 01, 2005 4:58 am    Post subject: how to populate 2d array with user entered values in c++? Reply with quote

for some reason values diagonal to each other have the same values.the code is correct i thnik are you sure that the entire code is actually correct; it may not be this part that causing the wrong output. it could be the print function as well. please include how you printed the values as well good luck
Back to top
CookieMonster



Joined: 30 Sep 2006
Posts: 8

PostPosted: Wed May 18, 2005 6:39 am    Post subject: how to populate 2d array with user entered values in c++? Reply with quote

I used java but and I always name my row and col that nameBut I checked and it works.int [] [] mat1 = new int [3][3];//javafor (int row=0; row < mat1.length; row++) { for (int col=0; col <mat1.length; col++) { cin>>mat1[row][col]; } }The print out was the same for loops for (int row=0; row < 3; row++) { for (int col=0; col <3; col++) System.out.println( mat1[row][col] +"");//cout Smile }
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gregorygarver.com Forum Index -> Content Writing All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group