Help in C

FishBoy

Feeeesh
Joined
1 Aug 2004
Messages
1,685
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
 
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;
 
im getting negative numbers i dont get it, is it my code or my compiler, im using miracle c
 
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
 
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.
 
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
 
I have no clue either, not a c/c++ type myself :D I just knew you could get them.
 
just a question shouldnt this be in the programming section?
 
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.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back