以下是我迄今爲止的內容。我似乎無法弄清楚我做錯了什麼。我認爲我的輸入驗證功能也不正確。原始問題是:計算員工使用函數的淨工資 - C++
寫一個程序,計算員工的淨工資。該程序應提示用戶輸入工作小時數和小時工資。員工支付17.5%的工資總額作爲社會保障。所有員工都支付20%的工資總額。工資總額低於2500美元的員工需支付工資總額的10%稅。你的程序應該使用以下功能;
a。 computeGross:此函數根據工作小時數和小時工資計算總薪水。計算的工資總額返回到主要功能。
b。 computeDeductions:此函數接受總工資作爲輸入,計算社會保障和稅收減免,並將總扣減額返回至主要功能
c。 computeNet:該函數接受總工資,扣除和打印總工資,總扣減額和淨工資。 d)。 validateHours:該函數用於輸入驗證。它確定用戶提供的小時數是否有效。在支付期間工作的小時數不能超過150,不能是負數。
e。 validateWage:該函數用於輸入驗證。它決定了用戶提供的小時工資是否有效。小時工資不得超過200,不能爲負數。
#include <iostream>
#include <iomanip>
using namespace std;
// Declare Functions
double computeGross(double hoursWorked, double hourlyWage);
double computeDeductions(double grossPay);
double computeNet(double grossPay, double deductions);
void validateHours(double hoursWorked);
void validateWage(double hourlyWage);
int main()
{
// Declare Variables
double hoursWorked = 0;
double hourlyWage = 0;
double grossPay = 0;
double deductions = 0;
double netSalary = 0;
// Get the hours worked and hourly wage
cout << "Please enter the amount of hours worked (HH.MM): " << endl;
cin >> hoursWorked;
cout << "Please enter in your hourly wage: $" << endl;
cin >> hourlyWage;
// Output the results
cout << fixed << setprecision(2)
<< "The net salary is: $" << netSalary << endl;
return 0;
}
// compteGross() function - get gross salary based on hours worked and hourly wage.
double computeGross(double grossPay, double hoursWorked, double hourlyWage)
{
return grossPay = hoursWorked * hourlyWage;
}
// computeDeductions() function - gets salary and calculates deductions
double computeDeductions(double deductions, double grossPay)
{
if(grossPay < 2500)
{
deductions = (grossPay * .10) * .175;
}
else
{
deductions = (grossPay * .20) * .175;
}
return deductions;
}
// computeNet() function - prints out gross salary,total deductions and net salary
double computeNet(double netSalary, double grossPay, double deductions)
{
netSalary = grossPay - deductions;
cout << "The gross salary is: $" << grossPay << endl;
cout << "The total deductions are: $" << deductions << endl;
cout << "The net salary is: $" << netSalary << endl;
return netSalary;
}
// validateHours() function - input validation; hours worked can;t exceed 150 or be neg.
void validateHours(double hoursWorked)
{
if(hoursWorked < 0 || hoursWorked > 150)
{
cout << "Error! Hours can't be negative or exceed 150\n";
}
}
// validateWage() - Input validation; wage can't exceed 200 or be negative
void validateWage(double hourlyWage)
{
if(hourlyWage < 0 || hourlyWage > 200)
{
cout << "Error! Wage can't be negative or exceed 200\n";
}
}
那你的*具體*問題是什麼? – OldProgrammer
當我運行程序時,我得到0作爲淨薪水,並且不,我的輸入不是0.我試圖弄清楚爲什麼是這樣。 – bradym55
請花點時間瞭解如何使用調試器。步驟通過代碼,檢查變量等 – OldProgrammer