# Thread: newb: what's wrong with my code?

1. ## newb: what's wrong with my code?

Code:
temp_var_a = 1 - (pop_i/growth);
temp_var_b = growth * temp_var_a;

printf("test temp a &#37;lf \n" , temp_var_a);
printf("test temp b %lf \n" , temp_var_b);

x=exp(temp_var_b);

final_val = pop_i * x;

printf(" final val is %d \n" , final_val);

I used two temp variables to display the calculations up to that point, so I know it works up to there...

but the exponent function isn't working
I'm guessing I'm using the exp function wrong? because the number doesn't come out right....

2. What types are the variables?

And what do you mean it doesn't come out right? What do you expect? And what do you get? Note that you're losing the decimal precision when you print it as "&#37;d". See http://www.cplusplus.com/reference/c...cmath/exp.html and http://www.cplusplus.com/reference/c...io/printf.html

3. And by "losing the decimal precision", zacs could very well mean "completely blowing away the answer", since %d will not print floating-point variables.

4. Code:
x=exp(temp_var_b);
There could be something wrong with the exp function.

5. Unknowns in your post are variable types of temp_var_a temp_var_b and final_val, code listing of exp() and use of %d when the return value from exp() may well be a float.

6. > There could be something wrong with the exp function.
yes... that's assuming that the C standard exp() from math.h wasn't used

In that case it'd be double, not float.

7. thankx guys...

I put %lf in instead, and it works perfectly....