What does " control reaches end of non-void function" means??
How to remove the warnings from out code ?
#include <bits/stdc++.h>
using namespace std;
int LinearSearch()
{
int ans=-1;
cout << "Enter the Size of the array: \n";
int n;
cin >> n;
cout << "Enter the array elements: \n";
int arr[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
int key;
cout << "Enter the key: \n";
cin >> key;
for (int i = 0; i < n; i++)
{
if (arr[i] == key)
{
cout << "the " << key << " is found at index " << i << endl;
}
return ans;
}
}
int main()
{
while (1)
{
cout << "\t Main Menu\n";
cout << "1. For Linear Search\n";
cout << "2. For Binary Search\n";
cout << "3. For First and last Occurence\n";
int ch;
cout << "Enter the choice: \n";
cin >> ch;
switch (ch)
{
case 1:
cout<< LinearSearch();
break;
case 2:
break;
case 3:
break;
default:
cout << "Invalid Choice OOps!! ";
break;
}
}
return 0;
}
AS I am trying to run it it is giving me Warning Why?? Error is: warning: control reaches end of non-void function [-Wreturn-type] How to resolve it?