// Torrez, Elaine CS1A Chapter 8 P. 487, #2
/********************************************************************************************
*
* DETERMINE LOTTERY WINNER
*
* ------------------------------------------------------------------------------------------
* This program determines whether any of a buyer's 10 lottery tickets is a winner.
* The program stores a fixed list of 10 "lucky" 5-digit combinations in an integer
* array. It then asks the user to enter this week's winning 5-digit number and
* performs a linear search through the array to see if any ticket matches.
* If a match is found, the program reports that the player has a winning ticket;
* otherwise, it reports that none of the tickets is a winner this week.
* ------------------------------------------------------------------------------------------
*
* INPUT
* winningNum : This week's winning 5-digit lottery number
*
* OUTPUT
* Message stating whether the player has a winning ticket or not
*
********************************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int SIZE = 10; // Number of lottery tickets
int tickets[SIZE] = { // Buyer's 10 "lucky" numbers
13579, 26791, 26792, 33445, 55555,
62483, 77777, 79422, 85647, 93121
};
int winningNum; // This week's winning number
bool isWinner = false; // True if a ticket matches
// ----------------------------------------------------
// INPUT: Get this week's winning 5-digit number
// ----------------------------------------------------
cout << "Enter this week's winning 5-digit lottery number: ";
cin >> winningNum;
// Simple input validation for a 5-digit positive number
while (winningNum < 10000 || winningNum > 99999)
{
cout << "ERROR: Enter a VALID 5-digit number (10000 - 99999): ";
cin >> winningNum;
}
// ----------------------------------------------------
// PROCESSING: Linear search through the ticket list
// ----------------------------------------------------
for (int i = 0; i < SIZE; i++)
{
if (tickets[i] == winningNum)
{
isWinner = true;
break; // Exit loop early if match found
}
}
cout << endl;
cout << fixed << setprecision(0);
// ----------------------------------------------------
// OUTPUT: Report if any ticket is a winner
// ----------------------------------------------------
if (isWinner)
cout << "Congratulations! One of your tickets is a WINNER." << endl;
else
cout << "Sorry, none of your tickets is a winner this week." << endl;
return 0;
}