The first mistake is that you are applying the discount before giving the bonus, which is the opposite of what the statement determines.
Second you’re calculating the wrong percentage anyway. You’re finding the percentage to be applied, dividing by 100, I don’t know why, and you’re not applying to the total.
As both the bonus, as the discount should be given on top of the basic salary, it is easy to do the bill. The formula needs to take the total value that is your 100%, so let’s normalize it to 1 (hence the division by 100 you were using, you already do it before you put it in the code). Then we normalize to 1 the percentages, that is 5%, turns 0.05 (divided by 100 again) and 7% turns 0.07. Then we add the total (1) with the bonus (0.05) and subtract the discount (0.07). Look at that simple formula.
If you want to visualize with the division:
salario = salario * (100 / 100 + 5 / 100 - 7 /100)
Obviously we can simplify this. I already simplified the code below. In the test done in ideone I have already made the whole account.
Finally, you’re using too many variables. It’s not an error, but it’s unnecessary.
In a real code several things could be done differently. I’m not going to say that the type float
is not suitable for monetary value.
#include <stdio.h>
int main() {
float salario;
printf("Digite o salario: ");
scanf("%f", &salario);
salario *= 1 + 0.05 - 0.07;
printf("\nO salario com desconto: %f", salario);
}
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
Please in addition to posting the code make it clear on the question what problem you encountered and what you have tried to do.
– hugomg
Vlw, the mustache already helped me !!!
– Luan Nunes