简体   繁体   English

有关空函数的问题

[英]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. 但是当我输入另一个每周工资时,FWI,FIA和NET PAY不会显示。

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 - 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

It's because your call to displayInfo() is outside of the while loop. 这是因为您对displayInfo()调用不在 while循环中。 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. 您需要将其移入循环并在其中使用适当的参数进行调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM