Lottery Ticket C++

A lottery ticket buyer purchases 10 tickets a week. always playing the same 10 5-digit "lucky" combinations. Write a program that reads the numbers from an input file, initializes an array with these numbers and then lets the player enter this week's winning 5-digit numbers (Use random number generator to generate 5 numbers in the range 1 through 49 for the winning combinationrather than letting the user enter the winning number combination).

The program should perform both, linear and binary search though the list of the player's numbers and report whether or not one of the tickets is a winner this week. You should present the user with the menu to find out if he/she is a winner through linear or binary search.

Here are the numbers:

11-18-20-24-25
8-10-23-32-36
1-6-12-18-34
23-29-31-32-34
1-15-17-23-32
4-6-13-25-27
8-9-26-29-34
14-17-19-24-30
1-8-25-28-29
13-17-24-29-33

Your code should be modular (use functions) and pass variables (by value/by reference) where appropriate.


Heres what i have so far; buttttttt after the user enters the lottery numbers it just closes...whyyy :(


/* A Lottery Program which checkscthe winning number,
and the buyer is the same as the result */

#include<iostream>

using std::cout;
using std::endl;
using std::cin;

int main(int argc, char *argv[])
{
int loop, counter = 10;
int thisresult[50] = {11,18,20,24,25,
8,10,23,32,36,
1,6,12,18,34,
23,29,31,32,34,
1,15,17,23,32,
4,6,13,25,27,
8,9,26,29,34,
14,17,19,24,30,
1,8,25,28,29,
13,17,24,29,33};
// This week lottery result

int number_lottery;
// Number of user lottery

cout << "How many numbers : ";
cin >> number_lottery;

int *user_lottery = new int[number_lottery];

for (loop=0;loop<number_lottery;loop++)
{
cout << "Enter the lottery Number : ";
cin >> *(user_lottery + loop);
}

cout << "\n\nComparison is being processed\n\n";
counter = 10;
while(counter > 0)
{
cout << counter << "!" << "\n";
counter--;
}

// -------------------------------------
// Comparison Part/Linear Search

for (loop=0;loop<10;loop++)
{
if ( *(user_lottery + loop) == thisresult[loop] )
{
cout << "\n\nCONGRATULATIONS, YOU ARE THE WINNER!";
cout << "\n\nThe number is " << *(user_lottery + loop);
}
}

delete [] user_lottery;

return 0;
}
after the user enters the lottery numbers it just closes...whyyy
because you didn't tell the computer to halt at the end. You can do it by
1
2
cout << "Press enter to exit";
cin.get();
before return 0;
I want to say you can also use system ("pause"), but I'll probably getted nagged by the more experienced programmers. To save the trouble, this is what Duas says about it:

Grumble.

Don't use system("anything"). It is slow. It is disliked by antivirus software. It is OS-dependent. It tags you as an absolute beginner. And it is a massively huge, gaping, ugly security hole.

If all you are doing is some silly homework assignment or playing with your own code, it is fine. But for everything else: please, please don't.


If you want to see other opinions and ways to pause the program look at http://www.cplusplus.com/forum/beginner/1988/
Last edited on
closed account (S6k9GNh0)
MeLB, you wouldn't need to wait if you would execute this in a seperate console. Code::Blocks also has something to prevent the console from closing so you wouldn't need to hardcode it in.

Also, this topic isn't specific to Windows. This should go into General C++ Programm... or Beginners.
/* A Lottery Program which checkscthe winning number,
and the buyer is the same as the result */

#include<iostream>

using std::cout;
using std::endl;
using std::cin;

int main(int argc, char *argv[])
{
int loop, counter = 10;
int thisresult[50] = {11,18,20,24,25,
8,10,23,32,36,
1,6,12,18,34,
23,29,31,32,34,
1,15,17,23,32,
4,6,13,25,27,
8,9,26,29,34,
14,17,19,24,30,
1,8,25,28,29,
13,17,24,29,33};
// This week lottery result

int number_lottery;
// Number of user lottery

cout << "How many numbers : ";
cin >> number_lottery;

int *user_lottery = new int[number_lottery];

for (loop=0;loop<number_lottery;loop++)
{
cout << "Enter the lottery Number : ";
cin >> *(user_lottery + loop);
}

cout << "\n\nComparison is being processed\n\n";
counter = 10;
while(counter > 0)
{
cout << counter << "!" << "\n";
counter--;
}

// -------------------------------------
// Comparison Part/Linear Search

for (loop=0;loop<10;loop++)
{
if ( *(user_lottery + loop) == thisresult[loop] )
{
cout << "\n\nCONGRATULATIONS, YOU ARE THE WINNER!";
cout << "\n\nThe number is " << *(user_lottery + loop);
}
}

system ("PAUSE");
return 0;
}



THANK YOU SO MUCHHHHHHH TO EVERYONE :))
it helped and it is compileing. butttt its not checking to see if the numbers are correct or not..
after you enter your lotto numbers it just shows the counter...which is suppose to compare the numbers you picked to the actual lottery numbers and let you know if you are a winner or not. =/










Computerquip:I remember putting the topic as C++ Cause this is what it is. Wouldnt lie.
/* A Lottery Program which checkscthe winning number,
and the buyer is the same as the result */

#include<iostream>

using std::cout;
using std::endl;
using std::cin;

int main(int argc, char *argv[])
{
int loop, counter = 10;
int thisresult[50] = {11,18,20,24,25,
8,10,23,32,36,
1,6,12,18,34,
23,29,31,32,34,
1,15,17,23,32,
4,6,13,25,27,
8,9,26,29,34,
14,17,19,24,30,
1,8,25,28,29,
13,17,24,29,33};
// This week lottery result

int number_lottery;
// Number of user lottery

cout << "How many numbers : ";
cin >> number_lottery;

int *user_lottery = new int[number_lottery];

for (loop=0;loop<number_lottery;loop++)
{
cout << "Enter the lottery Number : ";
cin >> *(user_lottery + loop);
}

cout << "\n\nComparison is being processed\n\n";
counter = 10;
while(counter > 0)
{
cout << counter << "!" << "\n";
counter--;
}

// -------------------------------------
// Comparison Part/Linear Search

for (loop=0;loop<10;loop++)
{
if ( *(user_lottery + loop) == thisresult[loop] )
{
cout << "\n\nCONGRATULATIONS, YOU ARE THE WINNER!";
cout << "\n\nThe number is " << *(user_lottery + loop);
}
}

system ("PAUSE");
return 0;
}



THANK YOU SO MUCHHHHHHH TO EVERYONE :))
it helped and it is compileing. butttt its not checking to see if the numbers are correct or not..
after you enter your lotto numbers it just shows the counter...which is suppose to compare the numbers you picked to the actual lottery numbers and let you know if you are a winner or not. =/




Topic archived. No new replies allowed.