Lo Shu Magic Square

This is the code I have so far and I keep getting errors thrown.

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
#include <iostream>

using namespace std;

int main()
{

void Sum(double);

 Sum(a); array[a[0]/3][a[0]%3] + array[a[1]%3] + array[a[2]/3][a[2]%3];

int LoShuMagic(int array[3][3])
{
	static const int t[8][3] = {{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}};

	int sum = sum(t[0]);
	int same = 1;
	for (int i = 1; i < 9; i++);
	{
		same = same && sum == Sum(t[i]);
	}

	system("pause");
	return same;
}
}

Last edited on
This is the code I have so far and I keep getting errors thrown.


I bet you do. This code won't compile.

When you paste your code, instead of just saying the you are getting lots of errors, tell us what the errors are. If they are compiler errors, paste them into your post, too. If you can compile and when you run the code you get errors, tell us what you are expecting and what you are getting.

In your case, you have a major problem separating function prototypes and function definitions. A function prototype should be outside the definition of another function. Also, one function should not be defined within another function.

The definition of function "main" goes from line 5 - line 26. There should be no function prototypes or other function definitions within these lines. However, line 8 is a prototype for function Sum. This should be before the beginning of main. The beginning of line 10 looks like a call to the function Sum, but the variable 'a' is never defined. I'm not sure what the end of line 10 is all about.

In lines 12 - 25 you have the definition of a new function LoShuMagic. The function looks reasonable after a quick glance, but it cannot be defined within main. Also, the function is never called anywhere.

Take a look at the tutorial page from this site that talks about functions:
http://www.cplusplus.com/doc/tutorial/functions/

Hopefully this will help you understand what you are trying to do.

Topic archived. No new replies allowed.