fork download
  1. //Cecilia Rangel CSC5 Chapter 7, P.447, #13
  2. //
  3. /**************************************************************
  4.  *
  5.  * LOTTERY APPLICATION
  6.  * ____________________________________________________________
  7.  * This program will randomly generate 5 number between 1 and 9 in
  8.  * an array for a lottery ticket.
  9.  *
  10.  *_____________________________________________________________
  11.  * INPUT
  12.  * user[SIZE] : INPUT the 5 digits of the user.
  13.  *
  14.  * OUTPUT
  15.  * lottery[SIZE] : OUTPUT the 5 digits of the lottery(randomnize)
  16.  * ***************************************************************/
  17. #include <iostream>
  18. #include <iomanip>
  19. #include <cstdlib>
  20. #include <ctime>
  21. using namespace std;
  22.  
  23. int main() {
  24. //Making variables
  25. const int SIZE = 5;
  26. int lottery[SIZE];
  27. int user[SIZE];
  28. //count to input arrays
  29. int count = 0;
  30. //bool value to check for matching digit
  31. bool match = true;
  32.  
  33. //Input the 5 digits of your lottery
  34. cout << "Enter your 5 digit of your lottery: ";
  35. for(count = 0; count < SIZE; count ++)
  36. {
  37. cin >> user[count];
  38. }
  39.  
  40. //Randomize the lottery number
  41. srand( time(0));
  42. for(count = 0; count < SIZE; count ++)
  43. {
  44. lottery[count] =rand()% 9 + 0;
  45. }
  46.  
  47. //OUTPUT the 5 digits of user's numbers
  48. for(count = 0; count < SIZE; count ++)
  49. {
  50. cout << user[count] << " ";
  51. }
  52.  
  53. //OUTPUT the 5 numbers of the randomize numbers
  54. cout << endl;
  55. cout << left;
  56. cout << setw(36) << "Lottery's winning numbers: ";
  57. for(count = 0; count < SIZE; count ++)
  58. {
  59. cout << lottery[count] << " ";
  60. }
  61.  
  62. //Checking for matching digits
  63. int total = 0;
  64. for(count = 0; count < SIZE; count ++)
  65. {
  66. if (user[count] != lottery[count])
  67. {
  68. match = false;
  69. }
  70. else
  71. total += 1;
  72. }
  73. //OUTPUT the matching digits
  74. cout << setw(37) << "\nThe amount of digits matched: " << total<< endl;
  75.  
  76. //Winning 5 Million Dollars if you got all 5 digits matched
  77. if (total == 5)
  78. cout << "Congratulation! you've won 5 Million Dollars!!!!!!\n";
  79. return 0;
  80. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Enter your 5 digit of your lottery: 1 0 2 0 -1103283768 
Lottery's winning numbers:          6 8 2 2 4 
The amount of digits matched:       1