fork download
  1. //Jonathan Estrada CSC5 Chapter 8, P.487, #2
  2. /*******************************************************************************
  3.  * DETERMINE LOTTARY TICKET
  4.  * _____________________________________________________________________________
  5.  * This program will receive a lottary ticket combination from the user and tell
  6.  * them if they won or not.
  7.  * _____________________________________________________________________________
  8.  * INPUT
  9.  * lottoNumbers n : all possible winning numbers
  10.  * SIZE : array size
  11.  * userLottoTicket : user lottary ticket number
  12.  * OUTPUT
  13.  * result : the return value of if it was found
  14.  * *****************************************************************************/
  15. #include <iostream>
  16. using namespace std;
  17.  
  18. int lottoMatchSearch( const int[], int, int);
  19. const int SIZE = 10;
  20.  
  21. int main() {
  22.  
  23. int lottoNumbers[SIZE] = {13579, 26791, 26792, 33445, 55555, 62483, 77777,
  24. 79422, 85647, 93121 };
  25.  
  26. int userLottoTicket;
  27. int result;
  28.  
  29. cout << "Please enter lotto ticket digits: ";
  30. cin >> userLottoTicket;
  31. cout << userLottoTicket << endl;
  32.  
  33. result = lottoMatchSearch(lottoNumbers, SIZE, userLottoTicket);
  34.  
  35. if(result == -1)
  36. cout << "You are not a winner." << endl;
  37. else
  38. cout << "Winning ticket. ";
  39.  
  40. return 0;
  41. }
  42. /*******************************************************************************
  43.  * Definition of function lottoNumbers.
  44.  * This function will look for possible matches to the lottary numbers in the
  45.  * array and return its value.
  46.  *
  47.  * *****************************************************************************/
  48. int lottoMatchSearch(const int lottoNumbers[], int SIZE, int userLottoTicket)
  49. {
  50. int index = 0;
  51. int positon = -1;
  52. bool found = false;
  53.  
  54. while(index < SIZE && !found)
  55. {
  56. if(lottoNumbers[index] == userLottoTicket)
  57. {
  58. found = true;
  59. positon = index;
  60. }
  61. index++;
  62. }
  63. return positon;
  64. }
Success #stdin #stdout 0.01s 5280KB
stdin
55555
stdout
Please enter lotto ticket digits: 55555
Winning ticket.