0
I’m not getting the expected result:
libraries ...
int main (void){
float c,r;
setlocale(LC_ALL,"");
printf("Digite o salário\n");
scanf("%f",&c);
printf("Digite o reajuste percentual:\n");
scanf("%f",&r);
r=r*0,01;
c=(c* r)+c;
printf("Salário reajustado: %.2f\n",c);
return 0;
}
The result always comes out with the first reading of the variable c
, which would be the starting salary, as I do for it to be "updated" in the operation just below without having to add more variables?
As follows it works:
libraries ...
int main (void){
float c,r,n;
setlocale(LC_ALL,"");
printf("Digite o salário\n");
scanf("%f",&c);
printf("Digite o percentual de reajuste:\n");
scanf("%f",&r);
n=c+r*c;
printf("Salário reajustado: %.2f\n",n);
return 0;
}
But in addition to the additional variable, the user would have to add the readjustment between a real number from 0 to 1, not to mention that I’m sure I’ll need to use this in the future. How can I solve?
Thanks bro, and thanks for the warning too, to reading my first book on C, and this program was requested in an exercise of the first chapter, I did the flowchart and when I went to pass the compiler had given it, could indicate me the other problems that exist in it?
– motorola
Money cannot be represented with
float
, is mixing withdouble
and a few other things that are only worth seeing when you’ve advanced further.– Maniero
Ahh, yes, in the book itself talks about the other types that would only be seen later, for now it was only seen float and int even, in the correction ta as I showed the exercise of the second way
– motorola
I hope not, books should not teach so informally, unless you make reservations.
– Maniero
I think the caveat was that the other types had not yet been seen, the book is "Algoritmos e Lógica de Programação em C, Uma Abordagem Didática" by Brazilian Silvio do Lago Pereira, publisher Érica.
– motorola