Theres matrix A, theres matrix B. I need to create matrix C which combines A and B. I get how thats done. But theres a problem as you can see in oic related. The last row is fucked and i cant fucking figure out why.
looking at line 36. assume i is 2 j is 5 what is B[i][j]?
Jaxson Roberts
and what is B[i][j-n] (given n is 4)
Gavin Martin
lol thats funny user but its actually a lowercase L. The thing our teacher made us do was to combine matrix A with B to form matrix C. Basically what the program does is ask if the number youre about to place is in the first half (j
Jacob Edwards
And no i and j start at 0 and they repeat until they reach n+l and m respectively
Justin Hernandez
Why would you use C arrays if you are learning C++? Also, why would you write do?
Parker White
i understand, but look closely at your B matrix and it's dimensions, and compare them what your actually trying to access.
look at lines 42 and 46. how high can i and j go? can you B matrix support that?
Andrew Morales
You haven't answered his question. B[i][j] is B[2][5], and B is a 4x4 matrix, accessing 5th element of it is erroneous.
Also fuck this is difficult to read. Have you heard about for loops?
Ryan Diaz
Bro i have no prior coding experience other than c++ we started on it. Do while is a command (or whatever its called) do { a } while(c) (c=condition) Its just another form of for(i=0;i
Jaxson Moore
That's fine, learning C parts of C++ first is a good approach. You should have used for instead of do while though.
Christian Turner
Im confused why b would be 2,5? i and j only go up to m and n respectively. Every loop the j goes only to 3 (which is the 4th element since j=0 counts as one) and then it repeats with i=1, the j going up to 3 again, then with i=2 etc etc.
Do While is another form of a for loop
Christopher Lopez
And as for why this is happening, my best guess is B is located before A in memory, so when you go out of bounds for B, you get values from A.
>Every loop the j goes only to 3 cum on m8 why do I know your code better than you? j goes to n+l-1 which is 7.
Ian Gutierrez
āiā can go up to m-1 which is 3. That means it repeats for i=0 up to i=3 so thats 4 elements.
Eli Young
>i and j only go up to m and n respectively interesting. so looking at this while ( j
Nicholas Gutierrez
+ screen pic instead screenshot
Caleb Rivera
Shit sorry i see my problem but why did that work in the first place without the j-n? in the first 3 rows it works correctly and it displays 4 in the second half even though j=4 which is out of bounds for B. Anyway thanks a lot for the help, i see i was just being retarded.
James Wilson
>why did that work in the first place without the j-n? c++ does not care how retarded you are. if you want to shoot yourself in the foot, it will set you up to take your legs with it and even help you pull the trigger as long as it compiles. and if it doesn't compile all you get is autistic screeching
Austin Robinson
Sorry i know its confusing, i changed some stuff on the second pic as well. n is the first half of the matrix C it has a value of 4, l is the second half also value of 4. n+l is 8 which is the amount of columns the matrix has. I do n+l-1 because i start j at 0, and that counts so even though j goes up to 7, the amount of times a character was printed in a row was 8 because it includes the time J was 0.
Ive found the problem and solved my confusion though.
Christian Ward
B is contiguous in memory in your case. Accessing B[0][4] (which is out of bounds) is same as accessing B[1][0]. So in effect while being out of bounds for row access, you were actually getting the right row numbers, just off by 1 for the column numbers. Change values in your matrices from all fives/fours to something identifiable (ie A from 1 to 16 and B from 101 to 116) and you can confirm it.
Juan Carter
Swap rows and columns in my post, I got a bit confused there myself.
Brayden Murphy
Ooooohhhhh that makes a lot of fucking sense. On the last loop, on the second half it was b[3][4] which made it b[4][0] which just doesnt exist. Im guessing that made it print A?