fork download
  1. // Andrew Alspaugh CS1A Chapter 7 p. 446 or 447. #13
  2.  
  3. /******************************************************************************
  4. CONFIRM LOTTERY NUMBERS
  5. ______________________________________________________________________________
  6. The program compares two parallel arrays, the first is the randomly generated
  7. lottery numbers and the second is the user inputted numbers. This program
  8. compares both and determines whether the user is the luckiest person alive
  9. or the stupidest person ever for playing the lottery.
  10.  
  11. All inputs and randomly generated values are 0-9
  12. _____________________________________________________________________________
  13. INPUTS:
  14. SIZE
  15. maxRange
  16. Lottery[]
  17. User[]
  18.  
  19. OUTPUS:
  20. WINNER
  21. ******************************************************************************/
  22. #include <iostream>
  23. #include <cstdlib>
  24. #include <ctime>
  25. using namespace std;
  26.  
  27. int main()
  28. {
  29. //DATA DICTIONARY
  30. const int SIZE = 5;
  31. const int maxRange = 10;
  32. int Lottery[SIZE];
  33. int User[SIZE];
  34.  
  35. bool WINNER = true;
  36.  
  37. int count = 0; //While Loop Counter
  38.  
  39. //INPUT
  40.  
  41. //Seed Random Numbers
  42. srand(time(0));
  43.  
  44. //Input Values of Lottery
  45. for(int count = 0; count < SIZE; count++)
  46. {
  47. Lottery[count] = rand() % maxRange;
  48. }
  49.  
  50. //Input User Values
  51. for (int count = 0; count < SIZE; count++)
  52. {
  53. cout << "Enter Value 0-9: " << endl;
  54. cin >> User[count];
  55. while (User[count] < 0 || User[count] > 9)
  56. {
  57. cout << "INVALID INPUT: Enter A Value Between 0 and 9 " << endl;
  58. cin >> User[count];
  59. }
  60. }
  61.  
  62. //PROCESS
  63.  
  64. //Compare Each Element in Parallel Arrays
  65. while (WINNER && count <SIZE)
  66. {
  67. if (Lottery[count] != User[count])
  68. WINNER = false;
  69. count++;
  70. }
  71.  
  72. //OUTPUT
  73.  
  74. //Output Lottery Value
  75. cout << "Winning Numbers Are: " << endl;
  76. for (int count = 0; count < SIZE; count++)
  77. {
  78. cout << Lottery[count] << " ";
  79. }
  80. cout << endl;
  81.  
  82. //Output User Value
  83. cout << "You Entered: " << endl;
  84. for (int count = 0; count < SIZE; count++)
  85. {
  86. cout << User[count] << " ";
  87. }
  88. cout << endl;
  89.  
  90. //IF WINNER OR LOSER
  91. if (WINNER)
  92. cout << "CONGRADULATIONS YOU ARE THE GRAND PRIZE WINNER" << endl;
  93. else
  94. cout << "HAHA YOU ACTUALLY THOUGHT YOU COULD WIN THE LOTTERY" << endl;
  95.  
  96. return 0;
  97. }
Success #stdin #stdout 0.01s 5320KB
stdin
1 2 3 4 5
stdout
Enter Value 0-9: 
Enter Value 0-9: 
Enter Value 0-9: 
Enter Value 0-9: 
Enter Value 0-9: 
Winning Numbers Are: 
3 2 5 2 7 
You Entered: 
1 2 3 4 5 
HAHA YOU ACTUALLY THOUGHT YOU COULD WIN THE LOTTERY