//Tahmidur Rahman CSC5 ch.8 pg. 487 #2
#include <iostream>
using namespace std;
/******************************************************************************
*
* Lottery Winners
* ____________________________________________________________________________
* A lottery ticket buyer purchases 10 tickets a week, always playing the same
* 10 5-digit "lucky" combinations. Write a program that initializes an array
* or a vector with these numbers and then lets the player enter tis week's
* winning 5 digit number. The program should perform a linear search through
* the list of the player's numbers and report whether or not one of the
* tickets is a winner this week. Here are the numbers:
*
* 13579 26791 2679, 33445 55555
* 62483 77777 79422 85647 93121
*_____________________________________________________________________________
* input
* winNums[] : array that stores all winning numbers
* lottery : stores value of the position
* entnum : enter lottery number
*
* Output
* "Sorry better luck next time" : if # entered wasn't lotter winner
* ""You're a winner!!!" : if # entered wasn the lotter winner
*
******************************************************************************/
/*******************************************************************************
*
* Void Search
* ____________________________________________________________________________
* A simple linear search should be used to locate the number entered by the
* user
* ____________________________________________________________________________
*
* const int array[] //Array that the stores all the ID numbers
* int SIZE //global constant for size of array
* int value //user entered ID #
* int ind = 0 //subsript to search array
* int position = -1 //record position of search value
* bool found = false //flag to indiacate if value was found
*
******************************************************************************/
int Search( const int[], int, int);
const int size = 10;
int main() {
//list of valid account numbers
int winNums[size] = {13579, 26791, 26792, 33445, 55555,
62483, 77777, 79422, 85647, 93121};
int lottery;
int entnum;
cout << "Enter the charge account number:\n";
cin >> entnum;
//search for the winning number
lottery = Search(winNums, size, entnum);
//if position returns -1
if (lottery == -1)
cout << "Sorry better luck next time.";
//if position returns anything but -1
else
{
cout << "You're a winner!!!\n\n";
}
return 0;
}
int Search( const int array[], int SIZE, int value)
{
int ind = 0; //subsript to search array
int position = -1; //record position of search value
bool found = false; //flag to indiacate if value was found
while(ind < SIZE && !found)
{
if (array[ind] == value) //if value is found
{
found = true; //set flag
position = ind; //record values subscript
}
ind++; //repeat process with next element
}
return position; //return position or -1
}