//Ava Huntington CS1A Chapter 8 Homework P. 487, #2
//
/*******************************************************************************
* DETERMINE LOTTERY WIN
* _____________________________________________________________________________
* This program will determine if a persons 10 "lucky" combinations for a weekly
* lottery matches the current weeks winning number using a linear search.
* _____________________________________________________________________________
* INPUT
* "lucky" combinations: given "lucky" combinations
* winning ticket: weekly winning lottery ticket
*
* OUTPUT
* win or lose: wether or not lucky combination matches winning #
******************************************************************************/
#include <iostream>
using namespace std;
int searchLottery(const int[], int, int);
const int SIZE = 10;
int main()
{
int combinations[SIZE] = {13579, 62483, 26791, 77777, 26792, 79422, 33445, 85647,
55555, 93121};
int result; //Matches winning number with lucky combo
int ticketNumber; // Winning number
cout << "*Lottery*" << endl;
cout << "Enter this weeks winning 5 digit number:" << endl;
cin >> ticketNumber;
//Search for account number
result = searchLottery(combinations, SIZE, ticketNumber);
if(result == -1){
cout << ticketNumber << " is not a winning number, better luck next week!" << endl;
}
else{
cout << ticketNumber << " is a winning number. Congratulations!" << endl;
}
return 0;
}
int searchLottery(const int list[], int numElms, int value)
{
int index = 0;
int position = -1;
bool found = false;
while(index < numElms && !found)
{
if(list[index] == value){
found = true;
position = index;
}
index++;
}
return position;
}
Ly9BdmEgSHVudGluZ3RvbiAgICAgICAgICAgICBDUzFBICAgICAgICAgICAgICBDaGFwdGVyIDggSG9tZXdvcmsgUC4gNDg3LCAjMgovLwovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKiBERVRFUk1JTkUgTE9UVEVSWSBXSU4KICogX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KICogVGhpcyBwcm9ncmFtIHdpbGwgZGV0ZXJtaW5lIGlmIGEgcGVyc29ucyAxMCAibHVja3kiIGNvbWJpbmF0aW9ucyBmb3IgYSB3ZWVrbHkKICogbG90dGVyeSBtYXRjaGVzIHRoZSBjdXJyZW50IHdlZWtzIHdpbm5pbmcgbnVtYmVyIHVzaW5nIGEgbGluZWFyIHNlYXJjaC4KICogX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KICogSU5QVVQKICogICAibHVja3kiIGNvbWJpbmF0aW9uczogICBnaXZlbiAibHVja3kiIGNvbWJpbmF0aW9ucwogKiAgICB3aW5uaW5nIHRpY2tldDogICAgICAgIHdlZWtseSB3aW5uaW5nIGxvdHRlcnkgdGlja2V0CiAqIAogKiBPVVRQVVQKICogICAgd2luIG9yIGxvc2U6ICAgICAgICAgICB3ZXRoZXIgb3Igbm90IGx1Y2t5IGNvbWJpbmF0aW9uIG1hdGNoZXMgd2lubmluZyAjCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCiNpbmNsdWRlIDxpb3N0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAogaW50IHNlYXJjaExvdHRlcnkoY29uc3QgaW50W10sIGludCwgaW50KTsKIGNvbnN0IGludCBTSVpFID0gMTA7CiAKaW50IG1haW4oKQp7CglpbnQgY29tYmluYXRpb25zW1NJWkVdID0gezEzNTc5LCA2MjQ4MywgMjY3OTEsIDc3Nzc3LCAyNjc5MiwgNzk0MjIsIDMzNDQ1LCA4NTY0NywKCQk1NTU1NSwgOTMxMjF9OwoKCWludCByZXN1bHQ7ICAgICAgICAgICAgICAgICAgLy9NYXRjaGVzIHdpbm5pbmcgbnVtYmVyIHdpdGggbHVja3kgY29tYm8KCWludCB0aWNrZXROdW1iZXI7ICAgICAgICAgICAvLyBXaW5uaW5nIG51bWJlcgoJCgljb3V0IDw8ICIqTG90dGVyeSoiIDw8IGVuZGw7Cgljb3V0IDw8ICJFbnRlciB0aGlzIHdlZWtzIHdpbm5pbmcgNSBkaWdpdCBudW1iZXI6Ii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