![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2007
Posts: 9
Rep Power: 0
![]() |
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. Last edited by C.B.; Jul 9th, 2007 at 12:10 AM. Reason: To add... |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 376
Rep Power: 0
![]() |
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.
__________________
I am Addicted to Linux! |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2007
Posts: 9
Rep Power: 0
![]() |
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. Last edited by C.B.; Jul 9th, 2007 at 12:16 AM. Reason: Sub 20 |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 376
Rep Power: 0
![]() |
No clue, didn't even know what the Sub 20 games were until I just googled it lol. Not a huge fan of soccer or sports in general. I like MMA (mixed martial arts).
__________________
I am Addicted to Linux! |
|
|
|
|
|
#5 | |
|
Newbie
Join Date: Apr 2007
Posts: 9
Rep Power: 0
![]() |
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. |
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Jun 2007
Posts: 129
Rep Power: 2
![]() |
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 |
|
Newbie
Join Date: Apr 2007
Posts: 9
Rep Power: 0
![]() |
//7-8-07
#include <stdio.h>
#include <stdlib.h>
int main( void )
main()
{
//Define Variables
int seed;
cin.get();
double r;
long int M;
double x;
int y;
int z;
int count;
//Code
seed = 10000;
srand(seed);
M = 1000;
for(count=1; count<=20; ++count)
{
r = ( (double)rand() / ((double)(RAND_MAX)+(double)(1)) );
x = (r * M);
y = (int) x;
z = y + 1;
printf("random number %3d %5f %5f %5d %5d\n",count,r,x,y,z);
}
}Ok 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. |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 |
|
Programmer
|
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. |
|
|
|
|
|
#10 |
|
Programmer
|
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.
cpp Syntax (Toggle Plain Text)
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Language display in program | Prm753 | C++ | 3 | May 30th, 2006 5:45 PM |
| Creating a program to test a program | sixstringartist | C | 8 | Jan 21st, 2006 1:15 PM |
| move program console window back | badbasser98 | C++ | 21 | Oct 18th, 2005 2:02 PM |
| Nonsense Name generator program | chillster13 | C | 14 | Jun 17th, 2005 2:05 AM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |