Previous Thread
Next Thread
Print Thread
Rate Thread
#17223 06/02/05 02:47 AM
Joined: Jun 2005
Posts: 3
G
Junior Member
Junior Member
G Offline
Joined: Jun 2005
Posts: 3
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?

Sponsored Links
▼ Sponsored Links ▼ ▲ Sponsored Links ▲
#17224 06/02/05 07:17 AM
Joined: Sep 2002
Posts: 553
UGN Super Poster
UGN Super Poster
Joined: Sep 2002
Posts: 553
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

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

main()
{
        int random_number;
        srand( (unsigned)time( NULL ) ); /*making sure we don't use the same seed and getting the same sequence of random numbers*/
        do
        {
        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.

#17225 06/02/05 11:25 AM
Joined: Sep 2002
Posts: 553
UGN Super Poster
UGN Super Poster
Joined: Sep 2002
Posts: 553
Forgot to close the main begin there, so put: "}" in the last line of the program.

#17226 08/06/05 10:46 AM
Joined: Jan 2005
Posts: 589
UGN Custodian
UGN Custodian
Joined: Jan 2005
Posts: 589
i think u just did his homework for him DG :p


Harry Potter Thread
if ur bored on the boards, get posting THERE!
#17227 02/08/06 11:54 PM
Joined: Feb 2006
Posts: 3
M
Junior Member
Junior Member
M Offline
Joined: Feb 2006
Posts: 3
A random number in 5-10 ,only need to do this(i think):

random_number=( 5+ rand()%6 );


what you are you do not see, what you see is your shadow.

Link Copied to Clipboard
Member Spotlight
None yet
Forum Statistics
Forums41
Topics33,840
Posts68,858
Members2,176
Most Online3,253
Jan 13th, 2020
Latest Postings
Top Posters
UGN Security 41,392
Gremelin 7,203
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Likes Received
Ghost 2
unreal 1
Crime 1
Ice 1
Dartur 1
Powered by UBB.threads™ PHP Forum Software 8.0.0