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.
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);
}
}
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.
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.
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.
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. =/