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 50 51 52 53 54 55 56 57
|
#include <iostream>
using namespace std;
// Function prototype
int searchList(int [], int, int);
//need to add a function to get data from the user
const int ARRAYSIZE = 18; //should be capitalized and it should also be declared in main
int array_pause; //this variable is declared twice see line 16 this should be deleted
int main()
{
int tests[ARRAYSIZE] = {5658845, 450125, 7895122, 8777541, 8451277,
1302850, 8080152, 4562555, 5552012, 5050552, 7825877, 1250255,
1005231, 654231, 3852085, 7576651, 7881200, 4581002};
//need a function call to a function that gets data from the user
int array_pause, //this variable is declared as a global variable
results;
//array_pause is being passed without a value
results = searchList(tests, ARRAYSIZE, array_pause);
cout<<" Enter a valid Charge Account"<<endl;
if (results == -1)
cout << "The number entered is InValid.\n"; //Display the number is InValid
else
{
cout << "The number entered is valid.\n"; //Displays the number is valid
cout << (results) << ".\n";
}
system("pause");
return 0;
}
int searchList(int list[], int numElems, int value)
{
int index = 0; // Used as a subscript to search array
int position = -1; // Used to record position of search value
bool found = false; // Flag to indicate if the value was found
while (index < numElems && !found)
{ //There is nothing stored in value at this point
if (list[index] == value) // If the value is 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
}
|