UGN Security

Guess the number game?

Posted By: Gothy

Guess the number game? - 06/02/05 09:47 AM

ok so i've worked at this a billion times and I still dont get it *BAH*. I used a random number generator then an if statement, so if the the generator hit a certain # between like 5-10 then it would say heads. I know get what im saying here, so is anyone willing to help a newb out?
Posted By: Digital Geek

Re: Guess the number game? - 06/02/05 02:17 PM

Well lots of people are willing to help if you'll and post your question right and be more specific.

Anyway, form what I understand you want to generate random numbers untill you find one between 5 and 10 and then dispaly a message heads and exit the program

#include <stdio.h>
#include <stdlib.h>

        int random_number;
        srand( (unsigned)time( NULL ) ); /*making sure we don't use the same seed and getting the same sequence of random numbers*/
        random_number=(rand()%21); /*generates a number between 0 and 20*/
        } while ((random_number<=5) &#0124;&#0124; (random_number>=10)); /*we generate numbers until we generate one between 5 and 10*/

        printf("Heads ! (%d)", random_number); /*when we exit the while loop our number is between 5 and 10 so we can print Heads and the number generated*/
To compile under linux use : gcc random.c -o random

Hope this helps you.
Posted By: Digital Geek

Re: Guess the number game? - 06/02/05 06:25 PM

Forgot to close the main begin there, so put: "}" in the last line of the program.
Posted By: EndGame

Re: Guess the number game? - 08/06/05 05:46 PM

i think u just did his homework for him DG :p
Posted By: munin_dk_cn

Re: Guess the number game? - 02/09/06 06:54 AM

A random number in 5-10 ,only need to do this(i think):

random_number=( 5+ rand()%6 );
© 2018 UGN Security Forum