Help in C

Discussion in 'Web Design & Coding' started by FishBoy, Nov 13, 2004.

  1. arrghh i can't take it i tried looking and thinking but i forgot how to creat a random number between 1 and 10 in C or any other languages, can any one remind me how to do it in C again plz asap thx
     
  2. Xie

    Xie - geek - Subscribed User Folding Team

    Messages:
    5,275
    Location:
    NY, USA
    I have no C experience but a 2sec google search for this ...
    Code:
    #include<math.h>
    srand(time(null));
    rand_num = (int)((rand()%RAND_MAX)*9.0) + 1;
    
     
  3. im getting negative numbers i dont get it, is it my code or my compiler, im using miracle c
     
  4. i think my compiler is dumb, can anyone point me out to a better C complier for windows, coz i tried compiling it on unix and i got all zeros
     
  5. LordOfLA

    LordOfLA Godlike!

    Messages:
    7,027
    Location:
    Maidenhead, Berkshire, UK
    you can get microsoft and borland command line compilers free, then there is dev-c++ and some other thing.

    Check out www.programmerstools.org run by a friend of mine, got links to the freebie programming stuff out there.
     
  6. ok i got the borlan complier, but how do i set the path and stuff like that coz i dont understand anything form the readme.txt, it's telling me to creat a .cfg and append the current path etc.. i dont know how to do those can you help me out
     
  7. LordOfLA

    LordOfLA Godlike!

    Messages:
    7,027
    Location:
    Maidenhead, Berkshire, UK
    I have no clue either, not a c/c++ type myself :D I just knew you could get them.
     
  8. Kush

    Kush High On Life!

    Messages:
    4,590
    Location:
    Montreal, Quebec
    just a question shouldnt this be in the programming section?
     
  9. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    Thread Moved
     
  10. delta4s

    delta4s BLACK HAWK ALOFT

    Messages:
    340
    Location:
    Bangalore, India
  11. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    http://bloodshed.net/ /* Dev-C++ */

    As for random ints.

    Code:
    int rndnmr (int high, int low) {
            return int ( rand() / (RAND_MAX + 1.0) * (high-low+1) + low );
    }
    Enjoy :). Do make sure to run srand( time(NULL) ); somewhere in your code before you use that function. Best bet is it place it in main() right after the decleration.