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
|
#include <iostream>
#include <ctime>
#include <cstdlib>
using std::cout; using std::cin; using std::endl;
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(NULL));
const int arraySize = 20;
int a[arraySize];
cout << "Lottery game! Guess a number: " << endl;
int wins[arraySize];
int userInput;
entry(userInput);
assign(a, arraySize);
draw(arraySize, wins);
check(userInput, arraySize, a);
printOut(a, arraySize);
}
void assign(int a[], int size) {
for (int i = 0; i < size; ++i)
a[i];
}
void draw(int arraySize, int wins[])
{
int count = 0;
while (count < arraySize)
{
int num = rand() % 100+1;
if (!check(num, arraySize, wins))
{
wins[count] = num;
++count;
}
}
}
bool check(int num, int arraySize, int wins[]) {
for (int i = 0; i < arraySize; ++i)
{
if (wins[i] == num)
return true;
}
return false;
}
void printOut(int wins[], int size)
{
cout << "winning numbers in lottery are" << endl;
for (int i = 0; i < size; ++i)
{
cout << wins[i];
}
}
void entry(int &userInput) {
cout << "Enter your guess <1-100>: " << endl;
cin >> userInput;
}
|