Debug program

Report a typo

Amy Wong has a great bank account, but she can't count at all. Previously, she had to calculate the percentage of the total amount and she managed to do that. But after the tax scale has become progressive, it was beyond her power. Bender volunteered to write her a tax calculation program for some $1,000. It takes one integer as input - income in dollars, and also produces one integer as output - tax payable. But the lazy robot never finished debugging the program. When Amy tried to hand over this data to the bureaucrat Hermes, he refused to accept it, because he immediately saw that the calculation was wrong. Try to cope with the task, which is beyond the power of the robot!

Tax calculation scale:
  • from the amount up to $ 10,000 inclusive, a tax of 5% is charged
  • 10% tax is charged from the amount from $ 10,000 to $ 100,000 inclusive
  • from the amount of $ 100,000, a tax of 15% is charged

For example, the amount of income in the current year is $200,000.

  1. Thus, from the amount of 200,000 200,000 - 100,000, a 15% tax equal to $ 15,000 will be charged
  2. From the amount of 100,000 100,000 - 10,000, a 10% tax equal to $ 9,000 will be charged
  3. From the amount of $ 10,000, a 5% tax equal to $ 500 will be charged
  4. The total tax on the entire amount of $ 200,000 will be 15,000+ 15,000 + 9,000 + 500= 500 = 24,500

Sample Input 1:

6000

Sample Output 1:

300

Sample Input 2:

20000

Sample Output 2:

1500

Sample Input 3:

200000

Sample Output 3:

24500
Write a program in Go
package main

import "fmt"

const (
maxTax = 15
middleTax = 10
lowTax = 5

maxLimit = 100_000
middleLimit = 10_000
)

func main() {
var amount int
fmt.Scanln(&amount)

tax := amount
switch {
case amount > maxLimit:
tax -= (amount - maxLimit) * maxTax / 100
amount = maxLimit
fallthrough
case amount > middleLimit:
tax -= (amount - middleLimit) * 100 / middleTax
amount = middleLimit
fallthrough
default:
tax -= amount * lowTax / 100
}
fmt.Println(tax)
}
___

Create a free account to access the full topic