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
|
// The Lottery
// Julia Mancuso
// 02-20-2018
#include <iostream>
#include <ctime>
#include <cstdlib>
using std::cout; using std::endl; using std::cin;
void assign(int[], int Size);
void draw(int, int[]);
bool check(int , int , int []);
void printOut(int[], int);
void entry(int &);
int main() {
srand(time(nullptr));
const int arraySize = 10;
int user[arraySize];
cout << "Did you win the lottery this week? Check it out now!" << endl;
int wins[arraySize];
int userInput;
assign(wins, arraySize);
draw(arraySize, wins);
entry(userInput);
check(userInput, arraySize, wins);
printOut(wins, arraySize);
}
void assign(int wins[], int Size) {
for (int i = 0; i < Size; ++i)
wins[i] = 0;
}
void draw(int arraySize, int wins[]) {
int count = 0;
while (count < arraySize) {
int number = rand() % 1000 + 1;
if (!check(count, arraySize, wins)) {
wins[count] = number;
count++;
}
}
}
bool check(int count, int arraySize, int wins[]) {
for (int i = 0; i < arraySize; ++i) {
if (wins[i] == count)
return true;
}
return false;
}
void entry(int user[]) {
int i;
cout << "Enter your 10 lottery numbers: ";
cin >> user[i];
}
void printOut(int wins[], int Size) {
cout << "Winning numbers in lottery are" << endl;
for (int i = 0; i < Size; ++i) {
cout << wins[i];
}
}
|