Binary Search- Whats wrong with this code? why run error?

#include
using namespace std;
int main() {
int n, key;
cin>>n;
int a[n];
for(int i=0; i<n; i++){
cin>>a[i];
}

cin>>key;

int s=0, e=n-1, mid;

while(s<=e){
	mid= (s+e)/2;

	if(key==a[mid]){
		cout<<mid;
		return mid;
	}
	else if( key> a[mid]){
		s= mid+1;
	}
	else{
		e=mid-1;
	}
}
cout<<-1;
return -1;

}

@alien
Your logic is correct, the only problem in the code is that you need to return 0 not mid or -1, returning anything other than zero indicates abnormal termination.
Rectified code: