fork download
  1. //Ava Huntington CS1A Chapter 8 Homework P. 487, #2
  2. //
  3. /*******************************************************************************
  4.  * DETERMINE LOTTERY WIN
  5.  * _____________________________________________________________________________
  6.  * This program will determine if a persons 10 "lucky" combinations for a weekly
  7.  * lottery matches the current weeks winning number using a linear search.
  8.  * _____________________________________________________________________________
  9.  * INPUT
  10.  * "lucky" combinations: given "lucky" combinations
  11.  * winning ticket: weekly winning lottery ticket
  12.  *
  13.  * OUTPUT
  14.  * win or lose: wether or not lucky combination matches winning #
  15.  ******************************************************************************/
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. int searchLottery(const int[], int, int);
  20. const int SIZE = 10;
  21.  
  22. int main()
  23. {
  24. int combinations[SIZE] = {13579, 62483, 26791, 77777, 26792, 79422, 33445, 85647,
  25. 55555, 93121};
  26.  
  27. int result; //Matches winning number with lucky combo
  28. int ticketNumber; // Winning number
  29.  
  30. cout << "*Lottery*" << endl;
  31. cout << "Enter this weeks winning 5 digit number:" << endl;
  32. cin >> ticketNumber;
  33.  
  34. //Search for account number
  35. result = searchLottery(combinations, SIZE, ticketNumber);
  36.  
  37. if(result == -1){
  38. cout << ticketNumber << " is not a winning number, better luck next week!" << endl;
  39. }
  40. else{
  41. cout << ticketNumber << " is a winning number. Congratulations!" << endl;
  42.  
  43. }
  44. return 0;
  45. }
  46.  
  47. int searchLottery(const int list[], int numElms, int value)
  48. {
  49. int index = 0;
  50. int position = -1;
  51. bool found = false;
  52.  
  53. while(index < numElms && !found)
  54. {
  55. if(list[index] == value){
  56. found = true;
  57. position = index;
  58. }
  59. index++;
  60. }
  61. return position;
  62. }
  63.  
  64.  
Success #stdin #stdout 0s 5284KB
stdin
77777
stdout
*Lottery*
Enter this weeks winning 5 digit number:
77777 is a winning number. Congratulations!