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 96 97 98 99 100 101
|
#include <iostream>
#include <random>
#include <ctime>
using namespace std;
void GenerateRandomNumbers(int Numbers[], int Count, int StartingNumber, int EndingNumber, default_random_engine* rn, bool bUnique = false)
{
int number = 0;
for(int x = 0; x < Count; x++)
{
number = (*rn)() % EndingNumber + StartingNumber;
if(bUnique)
{
for(int i = 0; i < x; i++)
{
if(number == Numbers[i])
{
number = (*rn)() % EndingNumber + StartingNumber;
i = 0;
}
}
}
Numbers[x] = number;
}
};
void OutputNumbers(int Numbers[], int Count)
{
cout<<endl<<"These are your numbers:"<<endl;
for(int x = 0; x < Count; x++)
{
cout<<Numbers[x];
if(x != (Count - 1))
cout<<", ";
}
};
int main()
{
int selection = 0;
char Playing = 'y';
int* Numbers = 0;
default_random_engine rn;
rn.seed((unsigned int)time(0));
cout<<"Lottery Number Generator."<<endl;
while(Playing == 'y')
{
delete[] Numbers;
cout<<"\nPlease choose the type of Game:"<<endl;
cout<<"Pick 3 (1):"<<endl;
cout<<"Pick 4 (2):"<<endl;
cout<<"Cash 5 (3):"<<endl;
cout<<"Mega Millions (4):"<<endl;
cin>>selection;
switch(selection)
{
case 1:
Numbers = new int[10];
GenerateRandomNumbers(Numbers, 10, 0, 9, &rn);
OutputNumbers(Numbers, 10);
break;
case 2:
Numbers = new int[10];
GenerateRandomNumbers(Numbers, 10, 0, 9, &rn);
OutputNumbers(Numbers, 10);
break;
case 3:
Numbers = new int[5];
GenerateRandomNumbers(Numbers, 5, 1, 34, &rn, true);
OutputNumbers(Numbers, 5);
break;
case 4:
Numbers = new int[5];
GenerateRandomNumbers(Numbers, 5, 1, 56, &rn, true);
OutputNumbers(Numbers, 5);
cout<<" And your Mega Number is: **"<< (rn() % 46) + 1 <<"**"<<endl;
break;
default:
cout<<"This is not a selection. Please try again."<<endl;
break;
}
cout<<endl<<endl<<"Do you want to generate more numbers? (y/n)"<<endl;
cin>>Playing;
}
cout<<"Thanks for playing! Hope you win!"<<endl;
delete[] Numbers;
return 0;
};
|