// Andres Guzman CSC5 Chapter 8, P. 487, #2
/******************************************************************************
*
* DETERMINE LOTTERY STATUS
* ____________________________________________________________________________
* This program will determine whether the inputed numbers for a lottery ticket
* match those of the winning numbers.
*
* Computation:
*
* Uses a linear search in the searchlist function to compare the values in the
* subscripts to the inputed values of the user. If equal, returns a positive
* status, and a negative status otherwise.
* ____________________________________________________________________________
*
* INPUT
* SIZE = Array Size
* lotterywins = The winning numbers for the lottery ticket
* lotterynum = Holds the inputed value for the lottery ticket number
*
* OUTPUT
* status = Displays the status of the lottery ticket
*
******************************************************************************/
#include <iostream>
using namespace std;
int searchlist(const int a[], int b, int c); //Function Prototype
const int SIZE = 10; //Array Size
int main()
{
//
//Initialization List
int lotterywins[SIZE] = {13579, 26791, 26792, 33445, 55555, 62483, 77777,
79422, 85647, 93121};
int lotterynum; //Holds Input Value for users Lottery Numbers
int status; //Holds Status of the lottery Ticket
//
//Prompt Input Display
cout << "Please enter this weeks winning lottery number: ";
cin >> lotterynum;
//
//Input Validation
while(lotterynum < 0)
{
cout << "Cannot Be Negatives. Please Try Again." << endl;
cout << "Please enter this weeks winning lottery number: ";
cin >> lotterynum;
}
//
//Adds Function Results to Variable Status
status = searchlist(lotterywins, SIZE, lotterynum);
//
//Determines whether the inputed values are equal to the subscript
if(status == -1)
cout << "\nTicket is not a winner this week." << endl;
else
cout << "\nTicket is a winner this week!" << endl;
return 0;
}
/*******************************************************************************
* Adding Definition to the function. This function will search through the list
* of values in the array subscript and determine whether the value inside
* matches the inputed value of the user, in which case will then determine the
* status of the lottery ticket by using a linear search.
******************************************************************************/
int searchlist(const int a[], int b, int c)
{
int index = 0;
int position = -1;
bool found = false;
while (index < b && !found)
{
if(a[index] == c)
{
found = true;
position = index;
}
index++;
}
return position;
}