//Sam Partovi CS1A Chapter 8, P 487, #1
//
/*******************************************************************************
* VALIDATE ACCOUNT NUMBER
* ____________________________________________________________
* This program validates a given account number against a set of specified
* valid account numbers, and determines whether the number is part of the set or
* not.
* ____________________________________________________________
*INPUT
* NUMBER_COUNT: Array size for account numbers
* inputNum: Given number to be validated
* numArray: Array of valid account numbers
*OUTPUT
* validFlag: Flag to check for validity of numbers
******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
const int NUMBER_COUNT = 18; //INPUT - Array size for account numbers
int inputNum; //INPUT - Given number to be validated
//INPUT - Array of valid account numbers
int numArray[NUMBER_COUNT] = {5658845, 4520125, 7895122, 8777541, 8451277,
1302850, 8080152, 4562555, 5552012, 5050552,
7825877, 1250255, 1005231, 6545231, 3852085,
7576651, 7881200, 4581002};
bool validFlag; //OUTPUT - Flag to check for validity of numbers
//Prompt for account number input
cout << "Enter a charge account number:";
cin >> inputNum;
//Validate if inputNum is found in the array
for(int i = 0; i < NUMBER_COUNT; i++) {
if(numArray[i] == inputNum) {
validFlag = true;
}
}
//Display results based on flag value
if(validFlag == true) {
cout << "\n" << inputNum << " is a valid number.\n";
}
else cout << "\n" << inputNum << " is an invalid number.\n";
return 0;
}
Ly9TYW0gUGFydG92aSAgICAgICAgICAgICAgICAgICAgICBDUzFBICAgICAgICAgICAgICAgICAgICAgQ2hhcHRlciA4LCBQIDQ4NywgIzEKLy8KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKKiBWQUxJREFURSBBQ0NPVU5UIE5VTUJFUgoqIF9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwoqIFRoaXMgcHJvZ3JhbSB2YWxpZGF0ZXMgYSBnaXZlbiBhY2NvdW50IG51bWJlciBhZ2FpbnN0IGEgc2V0IG9mIHNwZWNpZmllZCAKKiB2YWxpZCBhY2NvdW50IG51bWJlcnMsIGFuZCBkZXRlcm1pbmVzIHdoZXRoZXIgdGhlIG51bWJlciBpcyBwYXJ0IG9mIHRoZSBzZXQgb3IKKiBub3QuCiogX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCipJTlBVVAoqIE5VTUJFUl9DT1VOVDogQXJyYXkgc2l6ZSBmb3IgYWNjb3VudCBudW1iZXJzCiogaW5wdXROdW06IEdpdmVuIG51bWJlciB0byBiZSB2YWxpZGF0ZWQKKiBudW1BcnJheTogQXJyYXkgb2YgdmFsaWQgYWNjb3VudCBudW1iZXJzCipPVVRQVVQKKiB2YWxpZEZsYWc6IEZsYWcgdG8gY2hlY2sgZm9yIHZhbGlkaXR5IG9mIG51bWJlcnMKKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxpb21hbmlwPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiBjb25zdCBpbnQgTlVNQkVSX0NPVU5UID0gMTg7ICAgLy9JTlBVVCAtIEFycmF5IHNpemUgZm9yIGFjY291bnQgbnVtYmVycwogaW50IGlucHV0TnVtOyAgICAgICAgICAgICAgICAgLy9JTlBVVCAtIEdpdmVuIG51bWJlciB0byBiZSB2YWxpZGF0ZWQKIAovL0lOUFVUIC0gQXJyYXkgb2YgdmFsaWQgYWNjb3VudCBudW1iZXJzCiBpbnQgbnVtQXJyYXlbTlVNQkVSX0NPVU5UXSA9IHs1NjU4ODQ1LCA0NTIwMTI1LCA3ODk1MTIyLCA4Nzc3NTQxLCA4NDUxMjc3LCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEzMDI4NTAsIDgwODAxNTIsIDQ1NjI1NTUsIDU1NTIwMTIsIDUwNTA1NTIsIAogICAgICAgICAgICAgICAg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