0
I was trying today to create a simple program and C with some colleagues and one of the questions was: No else if
it would really be necessary to put the validations precoAtual >= 30
and vendaMedia >= 500
...since the if
are you checking? Well, looking quickly yes to verify the equality in both conditions and another is that as the if
has a or (||
) so the condition would not be 100% valid or something like ...but we wanted to go deeper and have a justification with more property.. and nothing came out. Would anyone know how to justify it? I can actually refactor the code by removing these validations?
PS.: I did table test but could not complete anything.
#include <stdio.h>
#include <stdlib.h>
int main(){
float vendaMedia, precoAtual;
printf("Digite o preco atual:");
scanf("%f", &precoAtual);
printf("Digite o valor da venda media:");
scanf("%f", &vendaMedia);
if(precoAtual < 30 || vendaMedia < 500){
precoAtual = precoAtual * 1.10;
}
else if((precoAtual >= 30 && precoAtual < 80) || (vendaMedia >= 500 && vendaMedia < 1200)){
precoAtual = precoAtual * 1.15;
}
else{
precoAtual = precoAtual * 1.20;
}
printf("%.2f \n", precoAtual);
system("pause");
return 0;
}