//Roman Lara Delgado CSC5 Chapter 8, P.487, #1
//
/*******************************************************************************
*
* Determine Invalid Account Number
*_______________________________________________________________________________
* This program determines if an account number is invalid meaning it does not
* exist in a set of account numbers.
* ______________________________________________________________________________
* INPUT
* accNumber_user : Account number entered by the user.
*
* OUTPUT
* A message that says whether the account number entered
* is valid or not.
* ******************************************************************************
* FUNCTION
* ******************************************************************************
* int searchList(const int [], int, int)
* ------------------------------------------------------------------------------
* This function locates if a value exists in an array.
*
* PARAMETERS:
* array[] : receives the values of an array.
* size : receives the number of elements
* of the array.
* value : receives a value that the user
* wanted to determine whether the
* value exists in the array or not.
*
*******************************************************************************/
#include <iostream>
using namespace std;
int searchList(const int [], int, int); //Function prototype
const int SIZE = 18; //GLOBAL VARIABLE - Number of elements of an array.
int main () //Start main
{
//Array that stores the account numbers of the data base.
int accNumber_saved[SIZE] = {5658845, 8080152, 1005231, 4520125, 4562555,
6545231, 7895122, 5552012, 3852085, 8777541,
5050552, 7576651, 8451277, 7825877, 7881200,
1302850, 1250255, 4581002};
int accNumber_user; //INPUT - Account number entered by the user.
int results; //Variable that determines if a number is valid or not.
//Enter the account number by the user.
cout << "Enter your account number: " << endl;
cin >> accNumber_user;
//Assign a value to results by calling the function searchList
results = searchList(accNumber_saved, SIZE, accNumber_user);
//if results is -1, then the number is invalid.
if(results == -1)
{
cout << "The number is invalid.";
}
else //Otherwise is valid.
{
cout << "The number is valid.";
}
return 0;
} //End main
//searchList definition
int searchList(const int array[], int size, int value) //Start seachList
{
int index = 0; //subscript of the array
int position = -1; //To record position of search value
bool found = false; //Flag to indicate if the value was found
while (index < size && !found)
{
if (array[index] == value) //If the value us found
{
found = true; //Set the flag
position = index; //Record the value's subscript
}
index++; //Go to the next element
}
return position; //Return the position, or -1.
} //End searchList