| tyler22 (23) | |||
|
Hi all, I am currently reading Frank Luna's "Intro to 3D Game Programming". One of the exercises is to write a program that calculates the transpose of a matrix. Following is the start of my code for this exercise:
There is a problem with the way I am initializing the matrix array. I am not getting a compiler error, but the program crashes after you input the first value. Please tell me how to properly handle user input of the matrix elements. Thanks, tyler22 | |||
|
|
|||
| tntxtnt (83) | |
line 32 should be cin >> matrix[a][b];. That's why you shouldn't name i = rows; j = columns;and you must delete 2d array at the end of your program | |
|
|
|
| tyler22 (23) | |
| thanks tnt | |
|
|
|
| tyler22 (23) | |||
|
EDIT: * I realized that the transpose of an mxn matrix is an nxm matrix. That explains why it worked fine for square matrices. I fixed the problem and the program works as expected now.* I have another problem. I am not sure if I am deallocating the memory correctly or if the error is something else. Here is my new program:
For whatever reason, if I input a square matrix the program works as expected. Problems arise if I input matrices of different dimensions. For example, a 1x3 will crash when it tries to transpose, and a 4x2 will transpose part of the matrix correctly but the other elements will be crazy numbers (like -32777). If anyone can help me I would appreciate it. | |||
|
Last edited on
|
|||