Magic Square program, please help!

Been working on this magic square problem for a while now and I'm stuck, I have no idea what to do next, I'm pretty new to c++ so any help would be great. thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cstdlib>

using namespace std;

int main(void) {
    int n;

cout << "Enter a value for n" <<
     << "n cannot be an odd integer" << endl;

cin >> n;

void magic(n) {
 for row = 0 to n-1
 for col = 0 to n-1
 square[row][col] = 0
}

int main(void) {
  const n 
  row = 0;
  col = n/2;
}

 for (i = 1 to n^2) {
  square[row][col] = i
  row--
  col++ 
}

//compensate for the edges

if square[row][col] != 0
  col--
  row+=2

//compensate for the edges

}
}

//output the square

return 0;

Last edited on
closed account (NUj6URfi)
Why do you have two mains?
Umm that's a good question, I shouldn't need that first one. Like I said, I'm pretty lost.
so now I have this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cstdlib>

using namespace std;

  int n;

cout << "Enter a value for n" <<
     << "n cannot be an odd integer" << endl;

cin >> n;

void magic(n) {
 for row = 0 to n-1
 for col = 0 to n-1
 square[row][col] = 0
}

int main(void) {
  const n 
  row = 0;
  col = n/2;
}

 for (i = 1 to n^2) {
  square[row][col] = i
  row--
  col++ 
}

//compensate for the edges

if square[row][col] != 0
  col--
  row+=2

//compensate for the edges
}
}

//output the square
	cout <<  square <<  endl;

return 0;
}
You are way too new to C++ to go "that deep".
Follow up some tutorials about how to code.
You'll come back here and laugh at your code.
Yeah tell me about it, I'm an engineering major, and this is the only programming class I have to take, and it's the first programming class I've ever taken. And this is our second project, I'm kinda in over my head..
Topic archived. No new replies allowed.