2020年3月20日 星期五

2.3-Compute_The_Tax - lab

解題心得:
快樂簡單題~不過一開始不知為何有誤差,但多丟幾次就莫名其妙過了

程式碼:
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
 float income,tax;
 while (cin >> income)
 {
  if (income < 750)
   tax = income * 0.01;
  else if (income <= 2250)
   tax = 7.50 + (income - 750) * 0.02;
  else if (income <= 3750)
   tax = 37.50 + (income - 2250) * 0.03;
  else if (income <= 5250)
   tax = 82.50 + (income - 3750) * 0.04;
  else if (income <= 7000)
   tax = 142.50 + (income - 5250) * 0.05;
  else
   tax = 230.00 + (income - 7000) * 0.06;
  //tax += 1e-6;
  cout << fixed << setprecision(2) << tax << endl;
 }
    return 0;
}

沒有留言:

張貼留言