Binary search - first and last occurence

The code is showing compilation error . Help me solving. The code is :- #include<bits/stdc++.h>
using namespace std;

int first_occurence(int a[],int n,int key)
{
int S = 0;
int E = n-1;

int ans = -1;

while(S<=E)
{

int mid = (E-S)/2;

if(a[mid] == key)
{
ans = mid;
E = mid-1;
}
else if(a[mid] > key)
{
E = mid-1;
}
else
{
S = mid+1;
}
}
return ans;

}
int last_occurence(int a[],int n,int key)
{
int S = 0;
int E = n-1;

int ans = -1;

while(S<=E)
{
	
int mid = (E-S)/2;

if(a[mid] == key)
{
ans = mid;
S = mid+1;
}
else if(a[mid] > key)
{
E = mid-1;
}
else
{
S = mid+1;
}
}
return ans;

}
int main()
{
int arr[] = {1,2,5,8,8,8,8,8,10,12,15,20};
int n = sizeof(arr)/sizeof(int);

int key;
cin>>key;

cout<<first_occurence(arr,n,key)<<endl;
cout<<last_occurence(arr,n,key)<<endl;

return 0;
}

I have edited your code… Try to submit it now…