reset problem in C code [duplicate]

-3

I would like help with the code I have a problem that follows in the image:

I'musingthiscode:

#include<stdio.h>#include<stdlib.h>intmain(){floatCP,LP,PP,LA,AA,AT,AAZ,PL,PC,FP;intQA;printf("\nDigite os dados da picina");
    printf ("\nComprimento, Largura, Profundidade: \n");
    {
        scanf("%f,%f, %f", &CP, &LA, &AA);
        PL = 2*CP*PP;
        PC = 2*LP*PP;
        FP = CP*LP;
        AT = PL+PC+FP;
        AAZ = LA*AA;
        QA = ((AT/AAZ)*1.05);
    }
    printf("\nA quantidade de azulejos para o revestimento da piscina e: %f", QA);
    system("PAUSE");
}
    
asked by anonymous 27.04.2014 / 18:34

2 answers

0

In addition to the problem presented by @pmg, you are also not initializing the variables PP and LP , which caused the program to run with unknown values for these variables. Ironically, these values must have been extremely low when you ran your code (values such as 5.88639522e-039 and 1.12103877e-044 ), which in practice is zero.

Similarly, as the variables were not initialized, such values could have been extremely high, and therefore the result would be otherwise.

With this (considering PP and LP null), PL , PC and FP were also zeroed since they multiply values PP and LP .

PL = 2*CP*PP;
PC = 2*LP*PP;
FP = CP*LP;

And with that, AT will also be zero.

AT = PL+PC+FP;

And finally, QA too.

QA = ((AT/AAZ)*1.05);

With this, regardless of the input value, the result will be zero (since QA is zero):

printf("\nA quantidade de azulejos para o revestimento da piscina e: %f", QA);
    
27.04.2014 / 18:57
1

Mete

    if (scanf("%f%f%f", &CP, &LA, &AA) != 3) /* erro */;

Instead of

    scanf("%f,%f, %f", &CP, &LA, &AA);

Conversion "%f, %f, %f" means to read a float optionally preceded by spaces, a comma, another float (with optional space before), another comma, optional space, and another float with optional space.

With the input "10" the variables LA and AA are not assigned and the program does wrong accounts.

Better still and make the input with fgets() and then sscanf() to assign value to variables

printf("Valores? ");
if (!fgets(tmp, sizeof tmp, stdin)) /* error */;
if (sscanf(tmp, "%f%f%f", &CP, &LA, &AA) != 3) /* error */;
    
27.04.2014 / 18:49