Error in a simple program

Asked

Viewed 44 times

-1

#include <stdio.h>

int main()
    {
    float aguagasta, price, total;
    
    printf("Digite o valor de agua [em metros cubicos] gasta em sua casa:\n");
    scanf("%f", &aguagasta);
    
    if (aguagasta < '20' && aguagasta > 0)
    {
        price = 8.50;
    }
    else
    {
        price = 11;
    }
        
    aguagasta * price = total;
        
    printf("Voce tera que pagar %f.", total);

}

The program goes through the Debugger, but does not run normally, whenever I type any value, comes out 0.000000 in the final result. Please help.

  • yes, no value has ever been assigned to total. Is the total line not envied? would it be total = aguagasta * price;?

2 answers

2

The order of aguagasta * price = total; ta wrong. What you want is: total = aguagasta * price;

Take the quotes from 20in the if: if (aguagasta < 20 && aguagasta > 0).

1

Good afternoon brother, the beginning stretch if (aguagasta < '20' && aguagasta > 0) the single quotation marks of 20 must be removed, and the end of the code is incorrect, which is aguagasta * price = total; in reality is total = aguagasta * price; because you have to call the variable and present it with a value after being read

  • Yeah, you reversed the statement: incorrect: watery * price = total; correct total = watery * price;

Browser other questions tagged

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