//Ryan Shahriyarpour CS1A Carl Argila CH7 HW Q:13
/*****************************************************************************
*
* Lottery Application
*
*********************
*
* This program simulates a lottery. The array lottery holds 5 random digits
* (0 - 9). The user enters 5 digits into the array user. The program counts
* how many digits match in the same position and displays the lottery
* numbers. If all 5 match, the user is the grand prize winner.
*
* INPUT
* Five digits from the user
*
* OUTPUT
* The lottery digits, the number of matches, and a grand prize message
****************************************************************************/
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
const int SIZE = 5;
int main()
{
int lottery[SIZE];
int user[SIZE];
int matches = 0;
// Make the random lottery digits
srand(time(0));
for (int i = 0; i < SIZE; i++)
lottery[i] = rand() % 10;
// Input (only 0 - 9 allowed)
for (int i = 0; i < SIZE; i++)
{
cout << "Enter digit " << i + 1 << " (0-9): ";
cin >> user[i];
while (user[i] < 0 || user[i] > 9)
{
cout << "Must be 0 to 9. Re-enter: ";
cin >> user[i];
}
}
// Count the matches
for (int i = 0; i < SIZE; i++)
{
if (lottery[i] == user[i])
matches++;
}
// Output
cout << "\nLottery numbers: ";
for (int i = 0; i < SIZE; i++)
cout << lottery[i] << " ";
cout << "\nMatching digits: " << matches << endl;
if (matches == SIZE)
cout << "GRAND PRIZE WINNER!" << endl;
return 0;
}