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
|
#include <iostream>
#include <ctime>
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(){
//declare array and other variables
srand(time(NULL));
const int arraySize = 5;
int a[arraySize];
cout << "Lottery game! guess a number" << endl;
int wins[arraySize];
int userInput;
entry(userInput);
assign(a, arraySize); // fill array with -1
draw(arraySize, wins); // select 10 non-repeating random numbers
check(userInput, arraySize, a);
printOut(a, arraySize); // outputs seleced lottery numbers
}
void assign(int a[], int size){
for (int i = 0; i < size; i++)
a[i]=-1;
}
void draw(int arraySize, int wins[])
{
int count = 0;
while (count < arraySize)
{
int num = rand() % 100;
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 <0-99>: ";
cin >> userInput;
}
|