![]() |
Lottery Program
How could I create a program to Pick lets say a Number from as many other numbers I enter, at random? And another program to generate random numbers?
Also, I know how to program a little in C++ and I have a compiler and all. This program doesn't sound to complex in my opinion. Any help to make would be great. |
Well start by learning how to generate random number. Google the c++ rand function. You will get more help if you make an effort first. At the very least Google random number in c++ and then try and throw something together. If that that point you can't get something working, post what you have so far and we would all be glad to help you out.
|
This is plenty help, I'll do that right now and see what I can come up with.
Edit. I noticed your from Ontario have there been any Sub 20 games there? For the Sub 20 World Cup. |
Quote:
|
Quote:
Anyways, I've read so far and I like what I'm reading. I can create a number within a disired range and if im correct could I make it to where it would only be say 3 digit numbers? Then Use the rand function again to choose a number from one of those? Like maybe in a seperate program? The reason Im doing this is because I want to start a little lottery with my WoW guild. Say perhaps everyone that wants a ticket(number) Could send a Mail(sorry if youve never played WoW and dont understand) with the money for the ticket. Then as I receieve the mails, Ill generate a number for them and write it down so no one gets it. Then when its time for the drawing enter said numbers and have the prog pick one set randomly. |
the way i see this program working is:
* user puts in 5 numbers (5 for arguements sake) * validate the input to make sure there are only 5 and that they're numbers * store the result in an array * generate 5 random numbers and store them in an array * compare the two arrays to see if they're the same * if they're the same display congrats or bad luck this could be any ammount of numbers, including one - except with one you wouldn't use an array (or would you?) if this is wrong please correct me (i'm new to coding) |
:
//7-8-07Ok this is what i got so far. Can you tell me some problems with it? I put the int main( void ) so i could use the cin.get because the program closed as soon as i Tryed to use it. And now it wont decompile. |
You're writing C++. Don't use stdio.h and stdlib.h. Don't use printf. Use <iostream>, cin, and cout. cin.get () will pause the program at the point of the statement. Therefore, put if right before the return.
If you have additional functionality issues, you need to explain them. If your program won't compile, include the compiler errors and warnings. Make sure they are all turned on. Read the "How to Post a Question" thread. |
What is with the random cin.get()?
also, I would seed the generator with time, seeing as the seed is constant, the generator is not truly random. :
srand( static_cast<int>( time(0) )for casting, I would also use static_cast< type >( value ). Also like Dawei said, use std::cout instead of printf, as this is a C++ program, not C. |
I quickly made a solution for the first problem, it should compile from what i can tell, I'm at work, and don't have a C++ compiler handy. There is no error checking in this at all, and the quality of the code in general is lame, but I'm not gonna make a full out solution for a little thing like this.
:
|
| All times are GMT -5. The time now is 2:34 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC