
//Dione Torrevillas                 CS1A                 Chapter 8, P. 487, #1

/**********************************************************
 * Class: CS1A
 * Chapter 8 Homework - Programming Challenge #1
 * Title: Charge Account Validation
 *
 * Description:
 * This program uses linear search to check whether a charge
 * account number is in the list of valid account numbers.
 *
 * INPUT:
 * A charge account number entered by the user.
 *
 * OUTPUT:
 * A message saying whether the number is valid.
 **********************************************************/

#include <iostream>
using namespace std;

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

    int accountNumber;  //INPUT - Charge account number from user
    bool found = false;

    cout << "Enter a charge account number: ";
    cin >> accountNumber;

    // Check each array element until a match is found (linear search).
    for (int i = 0; i < SIZE; i++)
    {
        if (accounts[i] == accountNumber)
        {
            found = true;
            break;
        }
    }

    //OUTPUT - Display the result of the search.
    if (found)
        cout << "The charge account number is valid." << endl;
    else
        cout << "The charge account number is invalid." << endl;

    return 0;
}
