1. ## Read a 4x4 matrix from user input

I need to read in a user input matrix in the following format:

Please enter a 4x4 matrix one row at a time.

Row 1: 1 3 -1 0

Row 2: 2 4 1 0

Row 3: 3 2 -2 2

Row 4: 4 0 1 5

I need to use the function:
void getmatrix(double A[][4]);

I then have to call it from the function main().

I have other things to do but I think I can figure that stuff out if I can figure out how to read in the matrix.

Any help would be appreciated.

2. Search google for "matrix c++" or just matrices, or any combo of the three. Theres tons of tutorials and code. Its pretty simple too.

As for void getmatrix(double A[][4]);, I'm not sure why its called getmatrix, instead of setmatrix, but you could just create a temp array (matrix) in main() and when you're done use that as the parameter for getmatrix().

3. I'm not sure why its called getmatrix
...beause the function gets the matrix from the user.

JHaney,

Pretend the function prototype is this instead:

void getmatrix(double A[4]);

and you have to read in this data:

Row 1: 1 3 -1 0

How would you do it? Write the code, and get it to work.

Once you get that working, you should be able to put that in a for loop and do it 4 times by letting the leftmost index value in the original function prototype vary with the loop index.

4. Originally Posted by 7stud
...beause the function gets the matrix from the user.
A right, I was looking at it as if it were in a class.

Edit: Ignore my first post. I was so out of it I assumed this function was part of a class and you were trying to set the matrix in that class by calling a function, but could only put it in one line at a time.

5. Code:
```void getmatrix(double A[][4])
{
int row=0;

for(int i=0;i<4;i++)
{
cout << "Row " << i+1 << ": ";
for(int j=0;j<4;j++)
cin >> A[i][j];
}
}```
Is this something that you want to do? I had one sitting around, maybe it is useful for you to get the idea of how arrays are passed by reference

6. Hey jlf029,

What do you think you're doing? Knock it off.

7. Thanks J. Yours is what I'm looking for. thanks

8. Alright I'm stuck again. I now have to find the minor of a 4x4 matrix.

9. That link is good ^ except I had a good think about how I would find the minor but I can't seem to find a general solution. You would have to somehow use recursion. It's really hard to use loops as to find the minor you have to follow the rules of multiplication