fork download
  1. //Diego Martinez CSC5 Chapter 8, P.487, #2
  2. /*******************************************************************************
  3. * DISPLAY LOTTERY WINNERS
  4. * ______________________________________________________________________________
  5. * This program allows the user to enter this week's 5-digit lottery
  6. * number and checks whether it matches any of the 10 winning lottery ticket
  7. * numbers. It then displays a message whether or not the user has a winning
  8. * number.
  9. *
  10. * Computation is based on the Formula:
  11. * tickets[i] = winningNumber
  12. *______________________________________________________________________________
  13. * INPUT
  14. * 5-digit lottery number entered by the user
  15. *
  16. * OUTPUT
  17. * A message stating whether one of the lottery tickets is a WINNER or not
  18. *******************************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main()
  23. {
  24. // Array of lottery ticket numbers
  25. int tickets[10] = {
  26. 13579, 26791, 26792, 33445, 55555,
  27. 62483, 77777, 79422, 85647, 93121
  28. };
  29.  
  30. int winningNumber;
  31. bool winner = false;
  32.  
  33. // Ask user for winning lottery number
  34. cout << "Enter this week's winning 5-digit number: ";
  35. cin >> winningNumber;
  36.  
  37. // Linear search
  38. for (int i = 0; i < 10; i++)
  39. {
  40. if (tickets[i] == winningNumber)
  41. {
  42. winner = true;
  43. }
  44. }
  45.  
  46. // Display result
  47. if (winner)
  48. {
  49. cout << "Congratulations! One of your tickets is a WINNER!" << endl;
  50. }
  51. else
  52. {
  53. cout << "Sorry, none of your tickets matched this week's winning number." << endl;
  54. }
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5280KB
stdin
13579
stdout
Enter this week's winning 5-digit number: Congratulations! One of your tickets is a WINNER!