fork download
  1.  
  2. //Dione Torrevillas CS1A Chapter 8, P. 487, #2
  3.  
  4. /**********************************************************
  5.  * Class: CS1A
  6.  * Chapter 8 Homework - Programming Challenge #2
  7.  * Title: Lottery Winners
  8.  *
  9.  * Description:
  10.  * This program uses linear search to check whether one of
  11.  * the player's ticket numbers matches the winning number.
  12.  *
  13.  * INPUT:
  14.  * This week's winning five-digit lottery number.
  15.  *
  16.  * OUTPUT:
  17.  * A message saying whether a ticket is a winner.
  18.  **********************************************************/
  19.  
  20. #include <iostream>
  21. using namespace std;
  22.  
  23. int main()
  24. {
  25. const int SIZE = 10;
  26. const int tickets[SIZE] = {
  27. 13579, 26791, 26792, 33445, 55555,
  28. 62483, 77777, 79422, 85647, 93121
  29. };
  30.  
  31. int winningNumber; //INPUT - Winning lottery number
  32. bool winner = false;
  33.  
  34. cout << "Enter this week's winning five-digit number: ";
  35. cin >> winningNumber;
  36.  
  37. // Search the tickets one at a time using linear search.
  38. for (int i = 0; i < SIZE; i++)
  39. {
  40. if (tickets[i] == winningNumber)
  41. {
  42. winner = true;
  43. break;
  44. }
  45. }
  46.  
  47. //OUTPUT - Display whether a ticket matched.
  48. if (winner)
  49. cout << "Congratulations! You have a winning ticket." << endl;
  50. else
  51. cout << "None of your tickets won this week." << endl;
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 5352KB
stdin
77777
stdout
Enter this week's winning five-digit number: Congratulations! You have a winning ticket.