//Maxwell Brewer CS1A Chapter 7, p. 447, #13
//
/*******************************************************************************
* LOTTERY GAME
* _____________________________________________________________________________
* This program will generate a 5-digit lottery ticket and the user wins if
* the ticket number matches.
* _____________________________________________________________________________
* INPUTS
* lottery
* user
*
* OUTPUTS
* matching
*
* ****************************************************************************/
#include <iostream>
using namespace std;
int main() {
// Declare variables for the lottery and user tickets
int lottery[5];
int user[5];
int matching = 0; // Variable to keep track of matching digits
// Seed the random number generator
srand(time(0));
// Populate lottery array with random values from 0 to 9
for (int counter = 0; counter < 5; counter++) {
lottery[counter] = rand() % 10;
}
// Get ticket numbers from the user
cout << "Enter your lottery numbers separated by spaces [0-9]:\n";
for (int counter = 0; counter < 5; counter++) {
cin >> user[counter];
// Count matching digits as values are read into the user array
if (user[counter] == lottery[counter]) {
matching++;
}
}
// Display lottery ticket
cout << "\nHere is the winning ticket:\n";
for (int counter = 0; counter < 5; counter++) {
cout << lottery[counter] << " ";
}
// Display winning message or number of matching digits
if (matching == 5) {
cout << "\n\nCongratulations! You had the winning numbers! You are the grand prize winner!\n";
} else {
cout << "\n\nYou only had " << matching << " matching numbers!\n";
}
return 0;
}