Calculation in program C results in zero in any calculation value

Asked

Viewed 627 times

0

I’m trying to do a kwh calculation. I am using values in float and the value kwh*0.2 must be calculated, but the result is always zero. And I don’t see any errors in the code.

inserir a descrição da imagem aqui

  • Note that to make calculations with non-integer values the type of being float or double.

  • 1

    Avoid posting images with your code - paste the code itself, using the website’s formatting features.

2 answers

0

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

The correct form is

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

0


Don’t forget to initialize the variable

When you print the variable do not need to put its memory address

#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;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.