Thread: some help please..

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    15

    some help please..

    my c
    Last edited by lyojarhhs; 10-15-2006 at 12:10 PM.

  2. #2
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    hmmm... maybe more info? like what type do you use for all those variable ? (int, double, float etc)

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    Code:
    #include <stdio.h>
    #include <math.h>
    main ()
    {
    int size, level, temp, max_population, max_pop_generations, population, hours, k, k_size, k_temp, l_level, e, k_rate_of_change, generations ;
    
    max_population = 0 ;
    max_pop_generations = 0 ;
    generations = 0 ;
    population = 1 ;
    hours = generations * 20 / 60 ;
    e = M_E ;

  4. #4
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    that int is your problem...

    use float...

    try this
    Code:
    #include <stdio.h>
    
    int main() {
       int a = 10.0 / 3;
       printf("%d\n", a);
    
       float b = 10.0 / 3;
       printf("%f\n", b);
    
       return 0;
    }
    Last edited by yxunomei; 10-14-2006 at 08:35 PM.

  5. #5
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Code:
      population = 1 * ( M_E ^ (( 1 - k ) * generations )) ;
    Do note that ^ is not exponents. (It's a binary xor.) For exponents, lookup the function pow.

    And to further explain, integers, the type you were using, cannot hold numbers like M_E. (e is not an integer - it's rational.) To hold numbers like .25, pi, e, etc, use float or double. (double gives more precision.)
    Last edited by Cactus_Hugger; 10-14-2006 at 10:59 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed