所以我的教授要求我們制定一個計劃,根據投入的工資率和工作時間來計算預算。百分比由教授給出。另外,我對C++很陌生,所以請原諒我,如果這個垃圾。爲什麼這些簡單的函數給我天文大小的數字?
#include <iostream>
using namespace std;
int main()
{
int hours;
double Pay;
const double Net = hours * Pay;
const double Tax = Net * .14;
const double afterTax = Net - Tax;
const double Clothes = .1 * afterTax;
const double Supplies = .01 * afterTax;
const double Bonds = .25 * afterTax;
const double Parents = Bonds/2;
cout << "Please enter hours worked \n";
cin >> hours;
cout << "Please enter hourly rate \n";
cin >> Pay;
cout << "Total Number of hours worked: " << hours << endl;
cout << "Total income before taxes: " << Net << endl;
cout << "Net Income: " << afterTax << endl;
cout << "Money Spent on clothes and accessories: " << Clothes << endl;
cout << "Money spent on school supplies: " << Supplies << endl;
cout << "Money spent on savings bonds: " << Bonds << endl;
cout << "Money spent by parents for savings bonds: " << Parents << endl;
cout << "Remaining: " << afterTax - Clothes - Supplies - Bonds << endl;
return 0;
}
對貨幣值使用'double'是錯誤的:[Money Pattern](http://www.di-mare.com/adolfo/p /money.htm)。 – 2015-02-07 20:12:37