gpt4 book ai didi

c++ - 关于void函数的问题

转载 作者:行者123 更新时间:2023-11-30 03:07:37 26 4
gpt4 key购买 nike

除了一件事,我知道我的代码是正确的。我输入第一份周薪后,一切都显示出来了。但是当我去输入另一个周薪时,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

最佳答案

这是因为您对 displayInfo() 的调用在 while 循环的之外。所以它只会被调用一次。您需要将它移到循环中并在其中使用适当的参数调用它。

关于c++ - 关于void函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5739263/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com