开发者

Question about void functions

I know my code is correct except one thing. After I enter the first weekly salary, everything is displayed. But when I go to enter another weekly salary, the FWI, FICA & NET PAY does not show.

Here's my code:

#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 - f开发者_Go百科wt - 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


It's because your call to displayInfo() is outside of the while loop. So it will only be called that one time. You need to move it into the loop and call it with the appropriate parameters there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜