floating point - C Program prints 0.00000 everytime but returns correct answer -


i have pretty simple code i'm having issues with. program calculates someone's weight in kilograms , displays it. however, every time run, printed answer comes 0.00000 returns correct answer. see wrong code?

#include <stdio.h> #include <math.h>  int main(void) {      float w;     float const wc=0.454;      printf("enter weight in pounds ");     scanf("%f", &w);       float wk = w * wc;      printf("your weight in kilograms is: %f", &wk);      return(wk); }  

you don't need pass address of variable argument format specifier print value. need change

 printf("your weight in kilograms is: %f", &wk); 

to

 printf("your weight in kilograms is: %f", wk); 

that said,

  1. always check return value of scanf(). without that, in case scanf("%f", &w); fails, you'll invoking undefined behavior you'll end using unitialized local variable float wk = w * wc; in float wk = w * wc;.

  2. please don't make return function. try stick return wk;.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -