should be getting the output on the picture**税表显示三列:年薪,税率和要缴纳的税额。下面的程序显示大部分代码需要计算个税表For Loop输出问题
#include <iostream>
using namespace std;
enter code here
int main() {
int INCOME_INCREMENT = 5000;
int annualSalary = 0;
double taxRate = 0.0;
int taxToPay = 0;
int startingAnnualSalary = 40000; 40000
int endingAnnualSalary = 60000; 60000
cout << "Enter first annual salary for the table: " << endl;
cin >> startingAnnualSalary;
cout << "Enter last annual salary for the table: " << endl;
cin >> endingAnnualSalary;
cout << "Enter the increment for the table: " << endl;
cin >> INCOME_INCREMENT;
for (int i = 0 ; i < 9 ; i++){
// Determine the tax rate from the annual salary
if (annualSalary <= 0) {
taxRate = 0.0;
}
else if (annualSalary <= 20000) {
taxRate = 0.10; // 0.10 is 10% written as a decimal
}
else if (annualSalary <= 50000) {
taxRate = 0.20;
}
else if (annualSalary <= 100000) {
taxRate = 0.30;
}
else {
taxRate = 0.40;
}
taxToPay = static_cast<int>(annualSalary -taxToPay * taxRate); // Truncate tax to an integer amount
cout << "Annual salary: " << annualSalary <<
"\tTax rate: " << taxRate <<
"\tTax to pay: " << taxToPay << endl;
// FIXME: Be sure to include the closing brace for the for loop
}
return 0;
}
呃,以及,你的问题是什么?怎么了?应该发生什么(没有外部链接)?请提供[最小,完整和可验证示例](http://stackoverflow.com/help/mcve)和具体问题... – Anedar
欢迎来到Stack Overflow!这听起来像你可能需要学习如何使用调试器来遍历代码。使用一个好的调试器,您可以逐行执行您的程序,并查看它与您期望的偏离的位置。如果你打算做任何编程,这是一个重要的工具。进一步阅读:** [如何调试小程序](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)** – NathanOliver
改变程序询问用户除了开始和结束的年薪以外,还可以使用增量。 再次使用2500的增量运行该程序。40000,45000,50000,55000和60000的条目是否与之前相同 –