1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <vector>
#include <string>
#include <time.h>
using namespace std;
const int lotteryDigits = 10;
const int SIZE = 5;
// Function Prototypes
int lottoGen(int[], int, int);
int userNumbers(int[], int);
int matchCounter(int[], int[], int);
void showAnswers(int[], int[]);
void wins(int);
int main()
{
// Variable Declarations
int matches = 0;
int numbers[5] = {0, 0, 0, 0, 0};
int correctNumbers[5] = {0, 0, 0, 0, 0};
//Calls the functions used to solve to problem (in proper order)
lottoGen(correctNumbers, SIZE, lotteryDigits);
userNumbers(numbers, SIZE);
matches = matchCounter(correctNumbers, numbers, matches);
showAnswers(correctNumbers, numbers);
wins(matches);
system("pause");
return 0;
} //end main
//This function produces the winning numbers of the lottery
int lottoGen(int correctNumbers[], int, int)
{
unsigned seed = time(0);
srand(seed);
for (int y=0; y<SIZE; y++)
{
correctNumbers[y] = rand() % lotteryDigits;
}
return correctNumbers[0], correctNumbers[1], correctNumbers[2], correctNumbers[3], correctNumbers[4];
} // end lottoGen
//This function retrieves the numbers requested by the user
int userNumbers(int numbers[], int)
{
cout << "This program will simulate a lottery.\n\n";
for (int y=0; y<SIZE; y++)
{
cout << "Enter a digit between 0 and 9:---> ";
cin >> numbers[y];
while (numbers[y]<0 || numbers[y]>9)
{
cout << "Error! Entry must be between 0 and 9:---> ";
cin >> numbers[y];
}
}
return numbers[0], numbers[1], numbers[2], numbers[3], numbers[4];
} // end userNumbers
//This function counts the number of matches the user has with their numbers and the winning numbers
int matchCounter(int correctNumbers[], int numbers[], int)
{
int matches = 0;
for (int x = 0; x < SIZE; ++x)
{
if (correctNumbers[x] == numbers[x])
matches = matches + 1;
}
return matches;
} // end matchCounter
//Shows the winning numbers to the user along with their numbers
void showAnswers(int correctNumbers[], int numbers[])
{
cout << "The winning numbers are as follows: " << correctNumbers[0] << " " << correctNumbers[1] << " " << correctNumbers[2] << " " << correctNumbers[3] << " " << correctNumbers[4] << endl;
cout << "The numbers you chose were: " << numbers[0] << " " << numbers[1] << " " << numbers[2] << " " << numbers[3] << " " << numbers[4] << endl;
} // end showAnswers
//Shows the user the amount of matches and if he/she has won
void wins(int matches)
{
cout << "The correct number of matches you had were: " << matches << endl;
if (matches != SIZE)
cout << "Sorry, you are not a winner today. :( Try again soon!" << endl;
else
cout << "CONGRATULATIONS! WE HAVE A WINNER AND THATS YOU!";
} // end wins
|