//Charlotte Davies-Kiernan              CS1A              Chapter 7 P. 447 # 13
//
/******************************************************************************
 * 
 * Display Lottery Game
 * ____________________________________________________________________________
 * This program will generate a random number in the range of 0 through 9 five
 * times while the user tries to guess what each number is going to be, 
 * simulating a lottery. If all numbers match, the user is a grand prize winner!
 * ____________________________________________________________________________
 * Input
 *   size      //A constant representing the number of digits in the lottery
 *   user      //Stores the 5 digits enetered by the user
 * Output
 *   lottery   //Stores the 5 randomly genertae lottery digits
 *   matches   //Keeps track of how many digits the user entered that matched with the lottery ones
 *****************************************************************************/
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
 
int main() {
//Data Dictionary
const int SIZE = 5;  //INPUT - A constant representing the number of digits in the lottery
int user[SIZE];      //INPUT - Stores the 5 digits enetered by the user
int lottery[SIZE];   //OUTPUT -Stores the 5 randomly genertae lottery digits
int matches = 0;     //OUTPUT - Keeps track of how many digits the user entered that matched with the lottery ones
 
//Generate Random Lottery Numbers (0-9)
srand(0);
for(int i = 0; i < SIZE; i++){
	lottery[i] = rand() % 10;
}
//Start Game
cout << "Welcome to the Lottery Game!" << endl;
cout << "Try to guess the 5 lottery digits (each between 0 and 9)." << endl;
cout << "Enter your 5 digits below" << endl;
 
//Get User's Guesses
for (int i = 0; i < SIZE; i++){
	cout << "Digit " << (i + 1) << ": " << endl;
	cin >> user[i];
	//Input Validation
	while(user[i] < 0 || user[i] > 9){
		cout << "Invalid input. Please enter a digit between 0 and 9: " << endl;
		cin >> user[i];
	}
}
 
//Compare 
for (int i = 0; i < SIZE; i++){
	if(lottery[i] == user[i]){
		matches++;
	}
}
 
//Reveal Lottery Numbers
cout << "Lottery Results:" << endl;
cout << "Lottery Numbers:";
for(int i = 0; i < SIZE; i++){
	cout << lottery[i];
}
 
cout << "\nYour numbers: ";
for (int i = 0; i < SIZE; i++){
	cout << user[i];
}
 
//Display Results
cout << "\nMatching digits: " << matches << endl;
if(matches == SIZE)
	cout << "CONGRATULATIONS! You're the GRAND PRIZE WINNER!" << endl;
else if (matches > 0)
	cout << "Nice try! You matched " << matches << " digits." << endl;
else
	cout << "No matches this time. Better luck next time!" << endl;
 
cout << "Thanks for playing!" << endl;
	return 0;
}