Lottery Program

Visual Studio won't tell me my errors right now. Could anybody help me with this lottery program?

#include <iostream>
#include <cstdlib>

const int LOTTERYA = 3;
const int LOTTERYB = 4;
const int LOTTERYC = 6;

using namespace std;

int main()
{
char LOTNUM;
cout << "Would you like pick 3, 4, or 6?";
cin >> LOTNUM;
switch (LOTNUM)
{
case '3':
{
int lotA[3];
unsigned seed = time(0);
srand(seed);

for (int count3 = 0; count3 < LOTTERYA; count3++)
{
lotA[count3] = rand() % 9 + 1;
}
int lotAU[3];
cout << "Enter your three lucky numbers";
for (int lucky3 = 0; lucky3 < LOTTERYA; lucky3++)
{
cin >> lotAU[lucky3];
}
cout << "The winning lottery numbers are" << lotA[0] << "" << lotA[1] << "" << lotA[2] << endl;
cout << "Your lottery numbers are" << lotAU[0] << "" << lotAU[1] << "" << lotAU[2] << endl;
}
case '4':
{
int lotB[4];
unsigned seed = time(0);
srand(seed);

for (int count4 = 0; count4 < LOTTERYB; count4++)
{
lotB[count4] = rand() % 9 + 1;
}
int lotBU[4];
cout << "Enter your four lucky numbers";
for (int lucky4 = 0; lucky4 < LOTTERYB; lucky4++)
{
cin >> lotBU[lucky4];
}
cout << "The winning lottery numbers are" << lotB[0] << "" << lotB[1] << "" << lotB[2] << "" << lotB[3] << endl;
cout << "Your lottery numbers are" << lotBU[0] << "" << lotBU[1] << "" << lotBU[2] << "" << lotBU[3] << endl;
}
case '6':
{
int lotC[6];
unsigned seed = time(0);
srand(seed);

for (int count6 = 0; count6 < LOTTERYC; count6++)
{
lotC[count6] = rand() % 9 + 1;
}
int lotCU[6];
cout << "Enter your four lucky numbers";
for (int lucky6 = 0; lucky6 < LOTTERYC; lucky6++)
{
cin >> lotCU[lucky6];
}
cout << "The winning lottery numbers are" << lotC[0] << "" << lotC[1] << "" << lotC[2] << "" << lotC[3] << lotC[4] << "" << lotC[5] << endl;
cout << "Your lottery numbers are" << lotCU[0] << "" << lotCU[1] << "" << lotCU[2] << "" << lotCU[3] << "" << lotCU[4] << "" << lotCU[5] << endl;
}
}
cout << "Thanks for playing!";
return 0;
}
Besides 'time': identifier not found? (compiled with Visual Studio :D) - you need to include time.h

Also you might want to add break; at the end of each case because if break is not included all statements following the matching case are also executed (i. e. if case '3' is executed, '4' and '6' will also be executed).

1
2
unsigned seed = time(0);
srand(seed);

You can put that at the beginning of the main function, no need for repeating.

lotAU[0] << "" << lotAU[1]
If you're not printing space between you there is no need for << "" <<, << is enough.

And pls use code tags....
Last edited on
Okay, sorry about the code tags, thank you!
Topic archived. No new replies allowed.