Sunday, August 2, 2009

Can u help with "srand" function in c...please?

ok my program is to produce any integer between 60 to 180.lets say X. then again i need to produce any integer wich should be between square root of X and square root of X+20. my program is like this:





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;math.h%26gt;


#define low_d 60


#define high_d 120


#define G 9.8


int


main(void)





{





double i, seed ;


double A, low_v, high_v,randomd ;





srand(time(0));








randomd = low_d + rand() % (high_d + 1 - low_d);


printf("\n%f\n ", randomd) ;








A = randomd * G;


printf("%f",A);





low_v = sqrt(A);


high_v = sqrt(A)+20;








srand(time(0));


printf("speed = %f",rand() % high_v + low_v);

















return(0) ;


}














so the prob is that it produces only integers as a random numbers. but i need real numbers. so when i use double and %f or %.2f it shows error " invalid operands to binary %"





any ideas??

Can u help with "srand" function in c...please?
I just did a complete search on my computer for "s rand srand" s r a n d, hidden or not, and found nothing relating to your computer problem. Sorry, I can not help you with your problem. Be aware that changing Windows functions or other settings, hidden or not, can be detremental to your computer, possibly only fixable by a computer programer that charges a lot of money.

magnolia

No comments:

Post a Comment