//Roman Lara Delgado CSC5 Chapter 7, P. 447, #13
//
/*******************************************************************************
*
* Simulate Lottery
* ____________________________________________________________________________
* This program generates a random set of lottery numbers and compares it
* with a set of inputted numbers. The program then determines how many numbers
* match and if it's a winning or losing set of numbers.
* _____________________________________________________________________________
* INPUT
* user[] : lottery numbers
*
* OUTPUT
* lottery[] : random set of lottery numbers
* digitsMatched : number of matching digits in lottery
*
* Winning or Losing Outcome of Lottery Ticket
*
******************************************************************************/
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
/***************************************************************************
* CONSTANTS
* -------------------------------------------------------------------------
* SIZE : Number of digits in lottery number
* ************************************************************************/
//Initialize Program Constants
const int SIZE = 5;
//Delcare Program Variables
int user[SIZE]; //INPUT - lottery numbers
int count; //COUNTER - loop counter
int randomNum; //CALC - Random generated
int lottery[SIZE]; //OUTPUT - random winning lottery number
int digitsMatched = 0; //OUTPUT - number of matching digits in lottery
//Get System Time
unsigned seed = time(0);
//Seed Random Number Generator
srand(seed);
//Generate Lottery Ticket Numbers
for (count = 0; count < SIZE; count++)
{
randomNum = 1 + rand() % 9;
lottery[count] = randomNum;
}
//Input Lottery Ticket Numbers
for (count = 0; count < SIZE; count++)
{
cout << "Enter Digit #" << count + 1 << ": " << endl;
cin >> user[count];
}
//Compare Lottery Ticket Numbers to Winning Numbers
for (count = 0; count < SIZE; count++)
{
if (lottery[count] == user[count])
{
digitsMatched++; //Increments counter variable if true
}
}
//Output Lottery Results
cout << endl;
cout << "Lottery Numbers: ";
//Output Digits Matching with Lottery
for (count = 0; count < SIZE; count++)
{
cout << lottery[count] << " ";
}
cout << endl;
cout << "Digits Matched: " << digitsMatched;
//Output Win or Lose
if (digitsMatched == 5)
cout << "\n!! Congrats you're a winner !!";
else
cout << "\nSorry, better luck next time.";
return 0;
}