What is wrong with my Program?

I need to turn this in for an assignment and I cant get it to compile

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
The problem above is that you try to define one function inside another. LoShuMagic() is contained inside main(). That is not possible, it must be moved outside.

See the tutorial on functions:
http://www.cplusplus.com/doc/tutorial/functions/
Note the first example, see how addition() and main() are separate.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

int addition (int a, int b)
{
  int r;
  r=a+b;
  return r;
}

int main ()
{
  int z;
  z = addition (5,3);
  cout << "The result is " << z;
}


Edit: Well, there are a few other issues too. For example function Sum() is not properly defined. The use of the various arrays needs work too.
Last edited on
Topic archived. No new replies allowed.