Source code does not compile

Asked

Viewed 264 times

-1

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {

    float parede, litros;

    printf ("Calcular litros de tintas  por metros quadrados.\n");
    printf ("Digite a metragem da parede(em metros ao quadrado):");
    scanf("%f", parede);

    if (litros = parede*2/10)
        printf("sao necessarios (litros):");
        scanf("%f", litros);

system ("pause");
return 0;
}

3 answers

1

In the scanf, it is necessary to use the "&":

scanf("%f", &parede);

The use of "if" is also not necessary, as you are assigning a value to the variable "liters", and not creating a condition:

litros=(parede*2)/10;

With this, in the final result, the printf should show:

printf("Sao necessarios (litros): %.2f", litros);

(The %.2f determined the number of decimal places that the program will show, which in this case are 2).

With this there is no need to use the "scanf" after this printf because the user will not type anything else, only the result will be printed.

I hope I’ve helped.

0

There are some problems in your code, for example scanf("%f", wall); it is necessary to allocate the value of the variable with &wall)/ another error is i IF it is not correct to use it since there is no condition in the program( it will receive value, calculate according to formula and only), the correct is liters = (wall*2)/10; liters will receive the wall value*2 / 10 and to display the values( printf("are necessary (litres)%. 2f: n ", litres); where (%.2f): will call the variable float with 2 digits after decimal place.

0

Try to use :

 if (litros = parede*2)/(10){
    printf("sao necessarios (litros):");
}
    scanf("%f", &litros);

Never forget to put & when using Scanf, if you want to print only two dpois numbers from the comma, use %.2f when printing. A good tip is to abandon devC++ (I think you’re using, due to system pause down there), I recommend using the Eclipse for C, and has the advantage of running on Linux as well.

Browser other questions tagged

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