# Thread: Help with sending a vector to a function

1. ## Help with sending a vector to a function

my magic square program is almost working i think. I need help with sending the current vector to my bool type function "isMagicSquare(a[])" that decides whether it is a magic square or not.

Code:
```#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

bool isMagicSquare(unsigned int a[]);

int main()
{

char input[10];
unsigned int numInput, i;
vector<int> a;

cout << "Enter a number ranging from 9-30: ";
cin.getline(input, 10);
numInput = atoi(input);
while(numInput < 9 || numInput >30)
{
cout << "Enter a number ranging from 9-30: ";
cin.getline(input,10);
numInput = atoi(input);
}

for(i=1; i<=numInput ;i++)
a.push_back(i);

while(next_permutation(a.begin(), a.end()))
{
if(isMagicSquare(a[]))
{
for(i=0; i<9;i++)
cout << a[i] << " ";
//if(i/9==1)
//	cout<<endl;
}
}

return 0;
}

bool isMagicSquare(unsigned int a[])
{
bool torf=false;

if(    a[0]+a[1]+a[2] == a[3]+a[4]+a[5]
&& a[3]+a[4]+a[5] == a[6]+a[7]+a[8]
&& a[0]+a[3]+a[6] == a[1]+a[4]+a[7]
&& a[1]+a[4]+a[7] == a[2]+a[5]+a[8]
&& a[0]+a[4]+a[8] == a[2]+a[4]+a[6]
&& a[0]!=a[1] && a[0]!=a[2]
&& a[0]!=a[3] && a[0]!=a[4]
&& a[0]!=a[5] && a[0]!=a[6]
&& a[0]!=a[7] && a[0]!=a[8]
&& a[1]!=a[2] && a[1]!=a[3]
&& a[1]!=a[4] && a[1]!=a[5]
&& a[1]!=a[6] && a[1]!=a[7]
&& a[1]!=a[8] && a[2]!=a[3]
&& a[2]!=a[4] && a[2]!=a[5]
&& a[2]!=a[6] && a[2]!=a[7]
&& a[2]!=a[8] && a[3]!=a[4]
&& a[3]!=a[5] && a[3]!=a[6]
&& a[3]!=a[7] && a[3]!=a[8]
&& a[4]!=a[5] && a[4]!=a[6]
&& a[4]!=a[7] && a[4]!=a[8]
&& a[5]!=a[6] && a[5]!=a[7]
&& a[5]!=a[8] && a[6]!=a[7]
&& a[6]!=a[8] && a[7]!=a[8])
torf=true;

}```

2. Code:
`bool isMagic(const std::vector<int> &a) { ...`

3. what is the format for this part:
Code:
`if(isMagicSquare(?)){...}`

4. Code:
`a`
gg

5. oh, i had the wrong code in the declaration of my function. im awesome. thanks for helping me. it works now.

Popular pages Recent additions