fork download
  1. //Andrew Alspaugh CS1A Chapter 8. P.487. #2
  2.  
  3. //Check For Lottery Winner
  4. /****************************************************************************
  5. This program accepts a user input as the winning lottery number. Then the
  6. program checks the array of ticket numbers to check for the winner.
  7. ____________________________________________________________________________
  8. INPUT
  9. SIZE: array size
  10. luckyValues: array name
  11. Winner: user input for winning lottery number
  12.  
  13. OUTPUT
  14. valid: displays true or false message
  15.  
  16. *****************************************************************************/
  17. #include <iostream>
  18. using namespace std;
  19.  
  20. int main()
  21. {
  22. //DATA DICTIONARY
  23. //Inputs
  24. const int SIZE = 10;
  25. int luckyValues[SIZE] = {13579, 26791, 26792, 33445, 55555, 62483, 77777, 79422, 85647, 93121};
  26. int Winner;
  27.  
  28. //Outputs
  29. bool valid = true;
  30.  
  31. //INPUT
  32. cout << "Enter This Weeks Winning 5-Digit Number: " << endl;
  33. cin >> Winner;
  34.  
  35. //PROCESS
  36. for (int count = 0; count < SIZE; count++)
  37. {
  38. if (luckyValues[count] == Winner)
  39. {
  40. valid = true;
  41. break;
  42. }
  43. else
  44. valid = false;
  45. }
  46. //OUTPUT
  47. if (valid == true)
  48. cout << "Congratulations You Won" << endl;
  49. if (valid == false)
  50. cout << "Better Luck Next Time" << endl;
  51.  
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5296KB
stdin
78946
stdout
Enter This Weeks Winning 5-Digit Number: 
Better Luck Next Time