Calculation in program C results in zero in any calculation value

0

I'm trying to do a kwh calculation, facul work. I'm using float values and the kwh * 0.2 value must be calculated, but the result is always zero. And I'm not seeing any errors in the code.

    
asked by anonymous 28.04.2016 / 20:27

2 answers

0

Do not forget to initialize the variable

When you print the variable not the need to put the memory address of it

#include <stdio.h>

int main()
{
    float calc = 0, kwh;
    printf("Escreva seu consumo em kwh: ");
    scanf("%f", &kwh);
    calc = kwh * 0.2;

    printf("Seu consumo e: %.2f \n", calc);

    return 0;
}
    
28.04.2016 / 22:26
0
printf("seu consumo e:%.2f \n", &calc);
// omite & para valor           ^ assim é endereço de memória

The correct way is

printf("seu consumo e:%.2f \n", calc);
    
17.05.2016 / 15:28