56. Purchase Discount Calculator
Difficulty: easy · Math
Problem
A shop gives a discount based on the purchase amount: | Amount | Discount | |---|---| | less than 1000 | 5% | | 1000 up to (but not including) 5000 | 10% | | 5000 or more | 15% | The final amount is `amount - amount * discount`. Print it rounded to 2 decimal places (exact halves round up).
Input
A single line containing the purchase amount, a non-negative number with at most 2 digits after the decimal point.
Output
Print the final amount with exactly two digits after the decimal point.
Example 1
Input: 800 Output: 760.00
Explanation: Below 1000 the discount is 5%: 800 - 40 = 760.00.
Example 2
Input: 3000 Output: 2700.00
Explanation: Between 1000 and 5000 the discount is 10%: 3000 - 300 = 2700.00.
Example 3
Input: 6000 Output: 5100.00
Explanation: At 5000 or more the discount is 15%: 6000 - 900 = 5100.00.
Constraints
- 0 <= amount <= 10^7
Solutions are judged against 3 sample and 11 hidden tests. Sign in to solve it · All problems