Write a personal income tax calculation program
The calculation method is: 1. No tax for 5,000; 2. 5,000-15,000: 10%; 3. 15,000-35,000: 15%; above 35,000, 20%;
For example, the user salary is 38,000, the calculation method is 50000.0 100000.10 200000.15 30000.20;
#include using namespace std; double shuishou(double); //函数原型 double basePay; //税前工资 const double fir_income_tax = 0.10; //第一档所得税率 const double sec_income_tax = 0.15;//第二档所得税率 const double tr_income_tax = 0.20;//第三档所得税率 const int base = 5000; //开始计算所得税下限 const int sec = 15000; //所得税第二档计算上限 const int tre = 35000; //所得税最高档计算下限 double income_tax; //实际所得税 int main() { cout << "请输入您的工资\n"; while (cin >> basePay) //判断用户输入是否有效 { if (basePay == 0 || basePay < 0) //如果用户输入0或小于零程序退出 break; else { double show; show = shuishou(basePay); cout << "您应交个人所得税为:"<> basePay; } } return 0; } double shuishou(double basePay) { if (basePay <= base) //如果用户工资小于等于5000,则不交所得税 return 0; else if (basePay > base&&basePay < sec) { //用户工资进入第一档税收计算范围 income_tax = (basePay - base)*fir_income_tax; return income_tax; } else if (basePay > sec&&basePay < tre) { //用户工资进入第二档税收计算范围 income_tax = (basePay - sec)*sec_income_tax + (sec - base)*0.10; return income_tax; } else if (basePay > tre) { //用户工资进第三档税收计算范围 income_tax = (basePay - tre)*tr_income_tax + (tre - sec)*0.15 + (sec - base)*0.10; return income_tax; } return 0; }
The above is the program I wrote. The problem with this program is that after displaying the income tax payable, you must hit Enter the next time you enter. How can I use cin to input content and press Enter to echo, instead of first Do you have to type again before the response is displayed?
Remove cin >> basePay;.
Thank you very much! I'll try