I've been trying to create a simple program and C with some colleagues and one of the questions was: In else if
would it really be necessary to put validations precoAtual >= 30
and vendaMedia >= 500
... since if
is checking? Well, quickly looking at yes to check equality on both conditions and another is that since if
has one or ( ||
) so the condition would not be 100% valid or something ... but we wanted to go deeper and have a better justification ... and nothing came out. Could anyone justify it? Can I actually refactor the code by removing these validations?
PS: I did test the table but could not finish 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;
}