Array Help?

This is my 2nd post (different problem this time) and with the last question I made, you guys answered me very well, so here I am again.
This time, I have to make a 6x6 "Magic Square"using arrays. I first made the program for a 3x3 and it works perfectly!
BUT, when I just doubled the stuff and tried to make it 6x6 it just doesn't work.. it goes straight to the "Press Any Key to Continue" and doesn't do anything.

The code may look tricky, but it's really not, there's a lot of copy/pasting in there for just copying the same function over and over:

O, BTW, if you don't wanna help that's ok. I'm just confused why it doesn't work, so if you have some free time to debug then awesome!

>> for (int x=0;x<=6;x=x+1)
Array indexes go from 0 to size - 1. Your loop goes from 0 to 6, but you are working with an array of size 6. This could cause your crash.

Also note that most C or C++ programmers use ++x instead of x=x+1. Either will work, but if you've learned the ++x notation you might as well use that instead.

Finally, <iostream.h> is not standard, so if you'd like people to help debug your code it might not compile on their compilers. Use <iostream> if you can instead, it is newer and standard and so it will work on all standards conformant compilers.

Were you saying that if I made an array of 5, like "int test[5];", the first character in the array would be at "test[0]" ?
I know C++ does something like that with the random # generator...

<iostream> doesn't work for me without the .h, but it is probably because I'm using Microsoft Visual C++ version 6.0 from '98. I'm too cheap to upgrade.
I changed it anyway so that people with the different version can use the code easier.

>> Were you saying that if I made an array of 5, like "int test[5];", the first character in the array would be at "test[0]" ?

Yes. Your changes are correct. I didn't run your code so I don't know if that was your problem or not, but either way your original code was wrong and your updates are right (assuming you did them correctly).

>> <iostream> doesn't work for me without the .h, but it is probably because I'm using Microsoft Visual C++ version 6.0 from '98.
It works in VC++ 6, you just need to specify the std namespace. The easiest way to do this for a small program is to add using namespace std; to the top of the file under the #includes. The best way to do this is to use std::cout and std::cin and std::endl instead of without the std::. Either one should be fine for this program.

You just got lucky with your 3x3 matrix. The errors I pointed cause undefined behavior, meaning you could get a crash, or it could appear to work now but give bad results later.

I see the problem with the 6x6 version. You are assigning random numbers from 1 to 36 into 6 variables, right? Then in checkrow1 you are checking to see if the 6 random variables add up to 36. If they don't, then you are calling assignrow1 again. The chances of the 6 variables adding up to 36 is very small since there are six of them in that range [1,36]. What is happening is that code keeps going back an forth between assignrow1 and checkrow1 without ever getting numbers that add up to 36.

Eventually you get a stack overflow. You are not allowed to keep calling functions deeper and deeper or you run out of stack space.

The solution is to use a loop inside assignrow1 that calls checkrow1 and tries again if checkrow1 returns false (assuming you know how to return a value from a function). This will avoid calling nested functions back and forth.

Of course, that will just make the code run, I think you might want to rethink your design that attempts to get 6 numbers that add up to 36.