How to create this expression in C #

0

At first, the program I did the calculation using the following expression:

valorComDescontos = valorTotal - (valorTotal * percentual);

Where valorTotal is a value assigned by the user (a variable), percentual is a fixed value ( 0.0229 ) and valorComDescontos is the value that will be calculated with INTEREST (% ). What I am trying to calculate now is this: the user will enter a value and the program should calculate as result the value that having the discounts will have the value entered by the user. By changing the calculation, I came up with the following expression:

valorTotal = valorComDescontos + (valorTotal * percentual)

But since the variable I will not have value is valorTotal* percentual , it could not be on both sides of the expression. How to calculate this?

Example (Previously):

valorTotal = 1000; #valor que o usuário inseriu
percentual = 0.0229; #valor FIXO

valorComDescontos = 1000 - (1000 * 0.0229);
valorComDescontos = 1000 - 22,9;
valorComDescontos = 977,1;

Example (How to calculate now):

valorComDescontos = 1000; #valor que seria dado pelo usuário
percentual = 0.0229; #valor FIXO

valorTotal = 1023,44; #seria esse o valor aproximado, onde descontando o percentual, chegaria ao valorComDescontos
    
asked by anonymous 15.02.2017 / 18:25

1 answer

1

Basic Mathematics:

valorComDescontos = valorTotal - (valorTotal * percentual)

You will have the values of valorComDescontos and percentual , looking for the value of valorTotal . First, put in evidence on the right side of equality:

valorComDescontos = valorTotal * (1 - percentual)

Now, if you divide both sides by 1 - percentual , you have:

valorComDescontos / (1 - percentual) = valorTotal

That is:

valorTotal = valorComDescontos / (1 - percentual)

Example:

valorComDescontos = 1000,00
percentual = 0,0229

valotTotal = 1000 / (1 - 0,0229)
valorTotal = 1000 / 0,9771
valorTotal = 1023,4367
valorTotal ~ 1023,44

As expected.

    
15.02.2017 / 18:41