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.
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;
}
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);