//Roman Lara Delgado CSC5 Chapter 8, P.487, #2
//
/*******************************************************************************
*
* Determine Lottery Winner
*_______________________________________________________________________________
* This program determines if a person, who has bought ten
* lottery tickets, has the winner ticket.
* ______________________________________________________________________________
* INPUT
* ticketWinner : The winner lottery ticket number.
*
* OUTPUT
* Indication if lottery ticket is a winner or loser.
* ******************************************************************************
* FUNCTION
* ******************************************************************************
* int searchList(const int [], int, int)
* ------------------------------------------------------------------------------
* This function locates if a value exists in an array.
*
* PARAMETERS:
* array[] : receives the values of an array.
* size : receives the number of elements
* of the array.
* value : receives a value that the user
* wanted to determine whether the
* value exists in the array or not.
*
*******************************************************************************/
#include <iostream>
using namespace std;
int searchList(const int [], int, int); //Function prototype
const int SIZE = 10; //GLOBAL - Number of elements of an array.
int main () //Start main.
{
int ticketUser[SIZE] = {13579, 62483, 26791, 77777, 26792, 79422,
33445, 85647, 55555, 93121}; //Tickets of the user.
int ticketWinner; //INPUT - The winner lottery ticket number.
int results; //Hold the position of an array.
//Enter the winner lottery ticket number.
cout << "Enter the winner ticket number: " << endl;
cin >> ticketWinner;
//Determine the position of the array that holds the user's winner ticket.
results = searchList(ticketUser, SIZE, ticketWinner);
if(results == -1) //If the array was not found
{
cout << "Your ticket is not a winner, play again.";
}
else //If the array was found.
{
cout << "YOU WON THE LOTTERY!";
}
return 0;
} //End main.
//searchList defintion
int searchList(const int ticketUser[], int numElems, int winner)
{
int index = 0; //Subscript of the array.
int position = -1; //To record position of search value.
bool found = false; //Flag to indicate if the value was found.
while (index < numElems && !found)
{
if (ticketUser[index] == winner) //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.
} //End searchList