// Andres Guzman CSC5 Chapter 8, P. 487, #1
 /******************************************************************************
 *
 *  DETERMINE NUMBER VALIDATION
 *  ____________________________________________________________________________
 *  This program will determine whether the inputed numbers in the account match
 *  those of the valid numbers.
 *
 *  Computation:
 *
 *  Uses a linear search in the linear function to compare the values in the
 *  subscripts to the inputed values of the user. If equal, returns a valid
 *  status, and a negative status otherwise.
 *  ____________________________________________________________________________
 *
 *  INPUT
 *  account = The valid numbers
 *  accountnum = Holds the inputed value for account numbers
 *
 *  OUTPUT
 *	array = Displays the status of the inputed numbers
 *
 ******************************************************************************/
#include <iostream>
using namespace std;

int linear(const int a[], int b, int c);		//Function Prototype
const int SIZE = 18;
int main()
{
//
//Initialization List
	int account[SIZE] = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
						 8080152, 4562555, 5552012, 5050552, 7825877, 1250255,
						 1005231, 6545231, 3852085, 7576651, 7881200, 4581002};
	int accountnum;		//Holds Input Value for users account numbers
	int array;			//Holds the results of the numbers
//
//Prompt Input Display
	cout << "Please enter a Number: ";
	cin >> accountnum;
//
//Input Validation
	while(accountnum < 0)
	{
		cout << "Cannot Be Negatives. Please Try Again." << endl;
		cout << "Please enter a Number: ";
		cin >> accountnum;
	}
//
//Adds Function Results to Variable Status
	array = linear(account, SIZE, accountnum);
//
//Determines whether the inputed values are equal to the subscript
	if(array == -1)
		cout << "\nInvalid." << endl;
	else
		cout << "\nValid" << endl;
	return 0;
}
/*******************************************************************************
 * Adding Definition to the function. This function will search through the list
 * of values in the array subscript and determine whether the value inside
 * matches the inputed value of the user, in which case will then determine the
 * status of the input numbers by using a linear search.
******************************************************************************/
int linear(const int a[], int b, int c)
{
	int index = 0;
	int position = -1;
	bool found = false;

	while (index < b && !found)
	{
		if(a[index] == c)
		{
			found = true;
			position = index;
		}
		index++;
	}
	return position;
}
