1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <iostream>
using namespace std;
int searchList(const int[], int, int);
int main()
{
string a;
int usrInput;
const int SIZE = 18;
int list[SIZE] = {5658845,8080152,1005231,4520125,4562555,6545231,
7895122,5552012,3852085,8777541,5050552,7576651,
8451277,7825877,7881200,1302850,1250255,4581002};
cout << "Enter an account number: ";
cin >> usrInput;
//search list for the users input
usrInput = searchList(list, SIZE, usrInput);
//check to see whats what
for(int i = 0; i < 9999999; i++){
if(usrInput == list[i]){
cout << "Your number is valid" << endl;
}else{
cout << "Invalid number" << endl;
}
return 0;
}
}
//using linear search, this will help find the users account number
int searchList(const int list[], int numElems, int value){
int index = 0;
int position = -1;
bool found = false;
while(index < numElems && !found){
if(list[index] == value){
found = true;
position = value;
}
index++;
}
return position;
}
|