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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/*
Josh Krynock CodeLab 73273
8.2: 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 this
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 26792 33445 55555
62483 77777 79422 85647 93121
*/
#include <iostream>
using namespace std;
//Function prototypes
int getPick();
int compareNumbers(const int[], const int, const int);
const int SIZE = 10; //Value to hold max number of lotto tickets
int lottoNUM[SIZE] = {13579, 26791, 26792, 33445, 55555,
62483, 77777, 79422, 85647, 93121};
int main()
{
int winloss; //Variable to hold win or loss result of comparison
int pick; //To hold gambler's picks
pick = getPick();
winloss = compareNumbers(lottoNUM, pick, SIZE);
if (winloss == 1)
cout << "YOU WON!";
else if (winloss == 0)
cout << "You did not win this week.";
return 0;
}
int getPick()
{
int choice;
do
{
cout << "Enter a 5 digit number for your lotto pick: ";
cin >> choice;
}
while (choice < 0 || choice > 99999);
return choice;
}
int compareNumbers(int winNUM[], int choice, int size)
{
int result; //Boolean value of win or loss comparison.
for (int count = 0; count < size; count++)
{
if (choice == winNUM[count] )
result = 1;
else if (choice != winNUM[count])
result = 0;
}
return result;
}
|