First of all, line 43 doesn't work for some reason i have to get it fixed so that numbers need to be in the range of 1-50 where u cannot pick the same numbers, and second of all, this works only for a ticket.However i have to have multiple tickets instead of 1, and i am kind of lost what to do here. Thanks for helping.
P.S: and yes i have to use classes
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
usingnamespace std;
constint SIZE = 6;
/*defines a class*/
class TexasLottery{
public:
int lottery[SIZE]; //array for the lottery
int user[SIZE]; //array for user input
int match; //variable to check matching numbers
int count; //variable for counting
void rangomgen(); //rangomgen() function to generate random numbers
void ticketInput(); //ticketiput function to get the input from user
void MatchNum(); //matchnum function to check the matching numbers
void Print(); //display the result
void GrandPrize(); //display the grand prize
};
/*randomgen function*/
void TexasLottery::rangomgen()
{
srand((unsignedint)time(0));
for (count = 0; count < SIZE; count++)
{
lottery[count] = 1 + rand() % 50;
}
}
/*ticketinput function*/
void TexasLottery::ticketInput()
{
cout << "Welcome to Texas Lottery\n";
cout << "Please enter your 6 numbers for your lottery ticket from 1 to 50: \n" ;
for (count = 0; count < SIZE; count++)
cin >> user[count];
if(user[count] == 0 || user[count] > 51 || user[count]==user[count])
cout << "Invalid entry please try again\n";
for (count = 0; count < SIZE; count++)
cin >> user[count];
}
/*matchnum function*/
void TexasLottery::MatchNum()
{
match = 0;
for(count = 0; count < SIZE; count++)
if(user[count] == lottery[count])
match++;
cout << "Here are the numbers drawn: ";
}
/*print function*/
void TexasLottery::Print()
{
for(count = 0; count < SIZE; count++)
cout << lottery[count] << " ";
cout << "\nYour numbers: ";
}
/*displays granprize*/
void TexasLottery::GrandPrize()
{
for(count = 0;count < SIZE; count++)
cout << user[count] <<" ";
cout << "\nMatching numbers: " << match << endl;
if(match == SIZE)
cout << "Your are the grand prize winner!!!\n";
}
void main()
{
TexasLottery tx; //creates an object
tx.rangomgen();
tx.ticketInput();
tx.MatchNum();
tx.Print();
tx.GrandPrize();
}
Welcome to Texas Lottery
Please enter your 6 numbers for your lottery ticket from 1 to 50:
1 2 3 4 5 6
Invalid entry please try again
1 2 33 65 4 3
Here are the numbers drawn: 44 46 31 3 30 48
Your numbers: 1 2 33 65 4 3
Matching numbers: 0
Press any key to continue . . .