// sequential search for a specific number

#include <iostream>
#include <cstdlib>			// rand & srand
#include <ctime>			// time
using namespace std;

const int LENGTH = 5;			// length of the array

int main()
{
	int numbers[LENGTH];		// test scores
	int i = 0;			// loop variable
	int key = 0;			// value being searched for
	bool found = false;		// flag variable for finding the key value

	srand(1);			// or srand(time(NULL));

	for (i = 0; i < LENGTH; i++)
	{
		numbers[i] = rand() % 50 + 1;
		cout << numbers[i] << " ";
	}

	cout << "Enter a number that you'd like to search for: ";
	cin >> key;

	for (i = 0; i < LENGTH; i++)		// linear search for key value
	{

		if (numbers[i] == key)
		{
			cout << "Found it in position " << i << endl;
			found = true;
			break;			// exit the loop so we don't needlessly inspect more values
		}

	}

	if (!found)				// or     if (found == false)
	{
		cout << "You didn't find it " << endl;
	}

	system("pause");

	return 0;
}// end of main
