Help me to solve

Im supposed to identify the errors and compile and run the program

Task#1 - compile & correct the errors in this program

// Task#2 - Run the program to understand its operations
/* - Explain what this program does
<???here>
*/

// Task#3 - Modify the code so that it generate integers from 0 - 99
// using rand() function (see label TASK#3 below)
///////////////////////////////////////////////////////////


#include <iostream>
using namespace std;

// Linear search of an array

linearSearch( const int [], int, int );

int main()
{
const int arraySize = 100; // Elements present in an array

int a[ arraySize ], searchKey, element;

for ( x = 0; x < arraySize; x++ ) // TASK#3 - creates data in array
a[ x ] = 2 * x;

cout << "Enter integer search key:" << endl;
cin >> searchKey;
element == linearSearch( a, searchKey, arraySize );

if ( element != -1 )
cout << "Found value in element " << element << endl;
else
cout << "Value not found" << endl;

system("PAUSE");
return 0;
}

int linearSearch( const int array[], int key, int sizeOfArray )
{
for ( n = 0; n < sizeOfArray; n++ )
if ( array[ n ] == key )
return n;

return -1;
}
It still shows error after i identify and modify the code :

/*Malani Nair A/p ABKrishenan UK 22124
inear search consists of looking for a particular value in a collection.


using rand() function (see label TASK#3 below) */

#include <iostream>

using namespace std;

// Linear search of an array

int linearSearch(int [], int,int);

int main()
{
const int arraySize = 100; // Elements present in an array
int array[arraySize] = {0};

int x,a[x],searchKey,element,n;

for ( x = 0; x < arraySize; x++ ) // TASK#3 - creates data in array
a[ x ] = 2 * x;

cout << "Enter integer search key:" << endl;
cin >> searchKey;
element == linearSearch( a, searchKey, arraySize );

if ( element != -1 )
cout << "Found value in element " << element << endl;
else
cout << "Value not found" << endl;

return 0;
}

int linearSearch( const int array[], int key, int sizeOfArray, int n )
{
for ( n = 0; n < sizeOfArray; n++ )
if ( array[ n ] == key )
return n;

return -1;
}
Topic archived. No new replies allowed.