除了一件事,我知道我的代码是正确的。输入第一周工资后,一切都会显示出来。但当我再输入另一周工资时,FWI,FICA& NET PAY不显示。
这是我的代码:
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
void getSalary(double &salary);
void calcFedTaxes(double salary, double FWT_RATE, double FICA_RATE, double &fwt, double &fica);
void calcNetPay(double salary, double fwt, double fica, double &netPay);
void displayInfo(double fwt, double fica, double netPay);
int main()
{
//declare constants and variables
const double .2;
const double FICA_RATE = .08;
double salary = 0;
double fwt = 0;
double fica = 0;
double netPay = 0;
//get salary
getSalary(salary);
//calculate the federal taxes
calcFedTaxes(salary, FWT_RATE, FICA_RATE, fwt, fica);
//calculate net pay
calcNetPay(salary, fwt, fica, netPay);
//display , gross, taxes, and net
displayInfo(fwt, fica, netPay);
while (salary != 0)
{
cout << "Weekly salary: ";
cin >> salary;
} //end while
return 0;
} //end of main function
//*****function definitions*****
void getSalary(double &salary)
{
cout << "Weekly salary: ";
cin >> salary;
} //end of getSalary
void calcFedTaxes(double salary, double FWT_RATE, double FICA_RATE, double &fwt, double &fica)
{
fwt = salary * FWT_RATE;
fica = salary * FICA_RATE;
} //end of calcFedTaxes
void calcNetPay(double salary, double fwt, double fica, double &netPay)
{
netPay = salary - fwt - fica;
} //end of calcNetPay
void displayInfo(double fwt, double fica ,double netPay)
{
cout << "FWT: " << fwt << endl;
cout << "FICA: " << fica << endl;
cout << "Net: " << netPay << endl;
} //end of displayInfo
答案 0 :(得分:3)
这是因为您对displayInfo()
的呼叫在while循环外 。所以它只会被称为一次。您需要将其移动到循环中并使用适当的参数调用它。