Well I'm writing a code that will get a key from user and find that key, weather it is present in the array or not. . .
I'm using VS - 2012, I've never encourtered an error like this ..
when i build the project, it prompts an error
"error C2181: illegal else without matching if"<br />
whats' this error,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,?
#include "stdafx.h"
#include <iostream>
using namespace std;
void fill(int a[], int length)
{
for (int i = 0; i < length; i++)
{
cout << "Element #" << i+1 << endl;
cin >> a[i];
}
}
void print(int a[], int length)
{
cout << "A R R A Y Of 10 Elements .." << endl;
for (int j = 0; j < length; j++)
{
cout << a[j] << " | ";
}
}
void find_key(int a[], int length)
{
int key;
cout << "Find The Number: ";
cin >> key;
bool found = false;
for (int i = 0; i < length; i++)
{
if (key == a[i])
{
found = true;
}
if (found)
{
cout << "K E Y Present" << endl;
else
{
cout << "K E Y Absent" << endl;
}
}
}
}
int main()
{
const int length = 10;
int label[length];
fill(label, length);
print(label, length);
find_key(label, length);
system("pause");
return 0;
}