Thread: hasard number!!

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    Unhappy hasard number!!

    I'm a french beginner on luangage programming
    Can you help me to make a code to generate hasard please?
    i have suceed to choose a randown number with this code :

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    
    {
        long nombreMystere = 0;
        srand(time(NULL));
        nombreMystere = rand();
        do
        {
    
        printf("&#37;ld",nombreMystere);
        } while (getchar()!='Q');
    
        system("PAUSE");
        return 0;
    }
    _________________________
    what does i do if i want a randown number between 0-100?
    i dont want use any loops.
    ty for your help.
    Last edited by Salem; 10-06-2008 at 12:15 PM. Reason: Put code tags AROUND the code, not just anywhere, oh, and removed the colouring in as well

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Quote Originally Posted by sokkha View Post
    I'm a french beginner on luangage programming
    Can you help me to make a code to generate hasard please?
    i have suceed to choose a randown number with this code :

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    
    {
        long nombreMystere = 0;
        srand(time(NULL));
        nombreMystere = rand();
        do
        {
    
        printf("%ld",nombreMystere);
        } while (getchar()!='Q');
    
        system("PAUSE");
        return 0;
    }
    what does i do if i want a randown number between 0-100?
    i dont want use any loops.
    ty for your help.
    Reformatted post for readability.

    gg

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Code:
    nombreMystere = rand() &#37; 101;
    For including endpoints.
    Code:
    nombreMystere = rand() % 99+1;
    For excluding endpoints.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    What's a "hasard"?

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    It translates to "chance." In other words he is asking how to make a random number generator.

  6. #6
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by master5001 View Post
    It translates to "chance." In other words he is asking how to make a random number generator.
    I thought maybe he meant a "hazard number" like you see on the side of lorries carrying dangerous goods; but after reading the thread, yes, random numbers make more sense...
    Btw: Google Translate while not perfect, isn't all that bad at translation.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I didn't know this existed. My hat is off to you, Pete.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help getting program print out the digit in words
    By cosmiccomputing in forum C Programming
    Replies: 26
    Last Post: 04-24-2008, 08:28 AM
  2. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 09:27 AM
  3. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  4. parsing a number
    By juancardenas in forum C Programming
    Replies: 1
    Last Post: 02-19-2003, 01:10 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM