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
|
#include <iostream>
using namespace std;
int searchList (const int [], int, int);
const int SIZE =10;
int main ()
{
int tickets [SIZE]= {
13579, 26791, 26792, 33445, 55555,
62483, 77777, 79422, 85647, 93121 };
int winningNumber;
int results;
cout << "\nPlease enter this week's winning 5-digit number: ";
cin >> winningNumber;
results=searchList (tickets, SIZE, winningNumber);
if (results==-1)
cout << "None of your tickets is a winner.\n";
else
cout << "Your ticket is a winner this week." << endl;
return 0;
}
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=index;
}
index++;
}
system ("pause");
return position;
}
|