Re: lottery number thing problem
From: Chris Dams (chrisd_at_gamow.sci.kun.nl)
Date: 11/12/03
- Next message: Chris Theis: "Re: Palindrome (HELP)"
- Previous message: Karl Heinz Buchegger: "Re: [OT] ini files"
- In reply to: moi: "lottery number thing problem"
- Next in thread: Chris Theis: "Re: lottery number thing problem"
- Reply: Chris Theis: "Re: lottery number thing problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 12 Nov 2003 10:29:54 +0000 (UTC)
Hello,
"moi" <random1234_NOSPAM_@blueyonder.co.uk> writes:
>p.s. i am aware from some replies to earlier posts that some of the things
>like the includes' etc is a bit archaic but for the purposes of this
>assignment, i dont really need it pointing out. cheers.
So, if you are aware of that, why don't you change it? It looks a bit silly.
>bool checknum(int num, int lottery_numbers[5])
>{
> for (int x=0; x <= 5; x++)
> {
> //check number is not equal to any other number already in array
> //and is greater than zero.
> if (lottery_numbers[x] == num || lottery_numbers[x] == 0)
Why test if the number ==0? Why not generate numbers >0 to begin with?
> {
> return false; //the number is invalid. it is rejected.
> }
> }
> return true; //the number is valid. it is accepted
>}
>void DrawNumbers(int lottery_numbers[5])
>{
>int num_count = 0; //counter for number of valid numbers found.
> while (num_count <=5) //i.e. while all 6 numbers have not yet been drawn.
> {
> //initialise random number generator
> time_t t;
> srand(unsigned (time(&t)));
The srand should not be inside the loop. Move it out of it.
> int num = (rand()*49); //generate a random number between 0 and 49
This generates all kinds of things, except what you want. Think about it.
The rand() function returns a pseudo-random integer between 0 and RAND_MAX.
How would you make an integer between >0 and <= 49 from that with (almost)
equal probability? Or, if you like, try to figure out how to make the
probabilities exactly equal.
>void main(int lottery_numbers[5])
main should return an int. Furthermore why does it take in integer array
as an argument. What is wrong with int main()?
>{
Declare your lottery_numbers inside main. Like
int lottery_numbers[5]={-1,-1,-1,-1,-1}; .
Initialize with -1 to prevent discarding numbers because some random
memory location happened to already contain a valid lottery number.
Bye,
Chris Dams
- Next message: Chris Theis: "Re: Palindrome (HELP)"
- Previous message: Karl Heinz Buchegger: "Re: [OT] ini files"
- In reply to: moi: "lottery number thing problem"
- Next in thread: Chris Theis: "Re: lottery number thing problem"
- Reply: Chris Theis: "Re: lottery number thing problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|