0
In the code below I can receive values in the pay fields without cents (example: 1,800), but if I put (1,800,20) has error.
Detail I’m using setlocale(LC_ALL,"Portuguese");
.
printf("\nAntepenúltimo salário: ");
scanf("%f", &AntepenultimoSalario);
printf("\nPenúltimo salário: ");
scanf("%f", &PenultimoSalario);
printf("\nÚltimo salário: ");
scanf("%f", &UltimoSalario);
MediaSalario = (UltimoSalario + PenultimoSalario + AntepenultimoSalario) / 3 ;
if(tempoServico >= 6 && tempoServico <= 11){
printf("Ira receber 3 parcelas");
}else if(tempoServico >= 12 && tempoServico <= 23 ){
printf("Ira receber 4 parcelas");
}else if(tempoServico >= 24 ){
printf("Ira receber 5 ");
}else{
semdireito();
}
// printf("Media Salario: %f", MediaSalario);
if(MediaSalario < 1.22277){
SalarioFinal = (MediaSalario * 0.8) * 1000 ;
printf(" parcelas : %5.3f\n", SalarioFinal);
system("pause");
}else if(MediaSalario > 1.22278 && MediaSalario <= 2.03815){
SalarioFinal2 = (MediaSalario - 1.22278) * 1000;
SalarioFinal = (SalarioFinal2 * 0.5) + 978.22;
printf(" parcelas de R$ %2.f\n", SalarioFinal);
system("pause");
}else if(MediaSalario >= 2.03815){
printf(" parcelas de R$ 1.385,91\n");
system("pause");
}
Related: https://answall.com/q/219211/64969
– Jefferson Quesado
Look at my answer: https://answall.com/a/219465/64969, has explanation on monetary calculations using fixed point (
BigDecimal
and related) and floating point. I also mention a great Infiniteseries video about floating point numbers– Jefferson Quesado
I need specific guidance in the code above, please
– Guilhermezio
not use
float
for monetary units?– Jefferson Quesado
Utilise
double
in the case @Jeffersonquesado ?– Guilhermezio
Neither. It has the same problems. See the above-mentioned answer for more criticism of the use of this type of data.
– Jefferson Quesado
As I mentioned in the question I am beginner and need help applied in the code above
– Guilhermezio
That is why I am strongly recommending to understand criticism regarding the inappropriate use of a type of data formulated for scientific applications in contexts that are extremely sensitive to precision.
– Jefferson Quesado
I understood that this incorrect use
float
, but I don’t know which one to use– Guilhermezio
Fixed point notation. Decimal of arbitrary size. The most common options are these. Fixed point may not require structure, but beware of handling.
– Jefferson Quesado