fork download
  1. //Devin Scheu CS1A Chapter 8, P. 487, #2
  2. //
  3. /**************************************************************
  4. *
  5. * CHECK LOTTERY WINNER
  6. * ____________________________________________________________
  7. * This program determines if the user's winning number matches
  8. * any of the player's lucky combinations.
  9. * ____________________________________________________________
  10. * INPUT
  11. * winningNumber : The 5-digit winning number entered by the user
  12. *
  13. * OUTPUT
  14. * winStatus : Message indicating if the number is a winner or not
  15. *
  16. **************************************************************/
  17.  
  18. #include <iostream>
  19. #include <iomanip>
  20.  
  21. using namespace std;
  22.  
  23. int main () {
  24.  
  25. //Variable Declarations
  26. const int NUM_TICKETS = 10; //OUTPUT - Number of tickets
  27. long luckyNumbers[NUM_TICKETS] = {13579, 26791, 26792, 33445, 55555,
  28. 62483, 77777, 79422, 85647, 93121};
  29. long winningNumber; //INPUT - The 5-digit winning number entered by the user
  30. bool isWinner = false; //PROCESSING - Flag indicating if the number is a winner
  31. string winStatus; //OUTPUT - Message indicating if the number is a winner or not
  32.  
  33. //Prompt for Input
  34. cout << "Enter this week's 5-digit winning number: ";
  35. cin >> winningNumber;
  36. cout << winningNumber << endl;
  37.  
  38. //Linear Search for Match
  39. for (int i = 0; i < NUM_TICKETS; i++) {
  40. if (luckyNumbers[i] == winningNumber) {
  41. isWinner = true;
  42. break;
  43. }
  44. }
  45.  
  46. winStatus = isWinner ? "You have a winning ticket!" : "No winning ticket this week.";
  47.  
  48. //Separator and Output Section
  49. cout << "-------------------------------------------------------" << endl;
  50. cout << "OUTPUT:" << endl;
  51.  
  52. //Output Result
  53. cout << left << setw(25) << "Win Status:" << right << setw(15) << winStatus << endl;
  54.  
  55. } //end of main()
Success #stdin #stdout 0.01s 5200KB
stdin
26792
stdout
Enter this week's 5-digit winning number: 26792
-------------------------------------------------------
OUTPUT:
Win Status:              You have a winning ticket!