Can anyone please check my code of triplets

can you please check whats the problem in this logic.
#include
#include
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int i;
for(i=0;i<n;i++)
{
cin>>a[i];
}
int key;
cin>>key;
//triplets
sort(a,a+n);
int p=0;
int q=n-1;
while(q>p)
{
for(i=p+1;i<q;i++)
{
if(a[p]+a[q]+a[i]==key)
{
cout<<a[p]<<", “<<a[q]<<” and "<<a[i];
break;
}
if(a[p]+a[q]+a[i]>key)
{
q–;
break;
}
}
if(a[p]+a[q]+a[i]<key)
{
p++;
}
}
}