We need to come up with 2 formulas, one - will count the number of coins, the other - the final price after purchase. But the essence is as follows. The user has for example 1000 bucks, the price of one coin is 100 bucks. And when he wants to buy coins for 1000 bucks, the following should happen. When buying the first coin, the price should be 100 (that is, the initial one), but when he buys 2 coins, the price should already be 101 bucks, on the third coin 102 bucks and so on until he spends all the money.
The cycle can be solved in the program, but there the cycle does not fit in any way. Do not ask why just no way. You just need the formula and the only way.
In fact, it should look like this:
- column - the number of units (money) player
- column - the number of coins
- column - price
- 1000 - 0 - 100
- 900 - 1 - 101
- 799 - 2 - 102
- 697 - 3 - 103
- 594 - 4 - 104
- 490 - 5 - 105
- 385 - 6 - 106
- 279 - 7 - 107
- 172 - 8 - 108
- 64 - 9 - 109
- 0 - 9.58 - 109.58
But still the nuance is that the unit in the program is considered as 1е18. Ie 1000 bucks is 1000e18 and so on. The program does not work with a dot, only integers. If during calculations there will be numbers after a point, then it will throw out all these numbers and only an integer will give out during calculations, therefore, the unit is 1е18. Help come up with a formula.
You also need a reverse formula for falling prices and reducing coins - such as the user has sold all his coins!
Input data
- Current coin price
- The amount of money for which the user is ready to buy coins! (With the purchase)
- The number of coins that the user wants to sell (for the inverse of the sale of coins)