📅  最后修改于: 2022-03-11 14:44:57.843000             🧑  作者: Mango
#include
using namespace std;
int main()
{
//read payrate
cout << "Enter the pay rate for an hour: ";
float payrate;
cin >> payrate;
int Hours_Week[5], total_hours = 0;
//read hours worked for 5 weeks
for (int i = 0; i < 5; i++)
{
cout << "Enter the hours you worked week " << i + 1 << ": ";
cin >> Hours_Week[i];
total_hours += Hours_Week[i];
}
//read percent saving
cout << "Enter the percent of net income spent to buy saving bonds: ";
int percent_saving;
cin >> percent_saving;
//print income before taxes
cout << "\n\nIncome before taxex was " << float(total_hours) * payrate << endl;
//calculate income after taxes
float final_income = float(total_hours) * payrate * (1 - .14);
//print income after taxes
cout << "Income after taxes was " << final_income << endl;
//calculate money for new clothes
float new_clothes = final_income * .1;
cout << "Amount spent on new clothes was " << float(int(100 * new_clothes)) / 100 << endl;
//calculate money for school supplies
float school_supplies = final_income * .01;
//calculate money for saving bonds
cout << "Amount spent on school supplies was " << float(int(100 * school_supplies)) / 100 << endl;
float saving_bonds = final_income * (float(percent_saving) / 100);
cout << "Amount spent on saving bonds was " << saving_bonds << endl;
float parents_saving;
float net_saving = final_income - new_clothes - school_supplies;
//calculate money for parents saving
if (percent_saving == 0)
{
parents_saving = .01 * net_saving;
}
else if (percent_saving <= 25)
{
parents_saving = .25 * (saving_bonds) + .01 * (net_saving);
}
else
{
parents_saving = .40 * (saving_bonds) + .02 * (net_saving);
}
cout << "Amount parents spent on saving bonds was " << float(int(parents_saving * 100)) / 100;
}