//Marvyn Jesse De La Torre         CS1A Chapter 8 #1 pg. 487
//
/*************************************************************
*
* Determine Account Validation
*
* This program checks whether an account number is valid
* by searching through a list of accepted account numbers.
*
* Input:
*   num: The account number entered by the user
*
* Output:
*   Displays whether the account number is valid.
*************************************************************/

#include <iostream>
using namespace std;

int check(int arr[], int size, int num);

int main()
{
    int arr[] = {
        5658845, 4520125, 7895122, 8777541, 8451277,
        1302850, 8080152, 4562555, 5552012, 5050552,
        7825877, 1250255, 1005231, 6545231, 3852085,
        7576651, 7881200, 4581002
    };

    int size = sizeof(arr) / sizeof(arr[0]);
    int num;

    cout << "Enter an account number: ";
    cin >> num;

    int position = check(arr, size, num);

    if (position == -1)
    {
        cout << "Invalid account number." << endl;
    }
    else
    {
        cout << "Valid account number." << endl;
    }

    return 0;
}

int check(int arr[], int size, int num)
{
    int position = -1;
    int index = 0;

    while (position == -1 && index < size)
    {
        if (arr[index] == num)
        {
            position = index;
        }

        index++;
    }

    return position;
}