//Sam Partovi CS1A Chapter 8, P 487, #2
//
/*******************************************************************************
* COMPARE LOTTERY NUMBERS
* ____________________________________________________________
* This program compares a given set of lottery numbers against a winning lottery
* number and determines if the numbers match, in which case a win is decided.
* ____________________________________________________________
*INPUT
* SIZE: Array size for given lottery numbers
* winningNumber: Winning lottery number
* lotteryTickets: Array of given lottery numbers
*
*OUTPUT
* winFlag: Flag for matching numbers
******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
const int SIZE = 10; //INPUT - Array size for given lottery numbers
int winningNumber; //INPUT - Winning lottery number
bool winFlag; //OUTPUT - Flag for matching numbers
//INPUT - Array of given lottery numbers
int lotteryTickets[SIZE] = {13579, 26791, 26792, 33445, 55555, 62483,
77777, 79422, 85647, 93121};
//Initialize winFlag to false
winFlag = false;
//Prompt for winning number to be compared
cout << "Winning lottery number: ";
cin >> winningNumber;
//Linear search, winFlag is true if a match is found
for(int i = 0; i < SIZE; i++) {
if(lotteryTickets[i] == winningNumber) {
winFlag = true;
}
}
//Display results
if(winFlag == true) cout << "\nYou won!";
else cout << "\nYou were not a winner.";
return 0;
}
Ly9TYW0gUGFydG92aSAgICAgICAgICAgICAgICAgICAgICBDUzFBICAgICAgICAgICAgICAgICAgICAgQ2hhcHRlciA4LCBQIDQ4NywgIzIKLy8KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKKiBDT01QQVJFIExPVFRFUlkgTlVNQkVSUwoqIF9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwoqIFRoaXMgcHJvZ3JhbSBjb21wYXJlcyBhIGdpdmVuIHNldCBvZiBsb3R0ZXJ5IG51bWJlcnMgYWdhaW5zdCBhIHdpbm5pbmcgbG90dGVyeQoqIG51bWJlciBhbmQgZGV0ZXJtaW5lcyBpZiB0aGUgbnVtYmVycyBtYXRjaCwgaW4gd2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