C++ 需要帮助获得无效代码工作,并支付总工资吗
我需要以下代码帮助更正错误。它的主要功能是接收用户工作小时数,然后根据工作小时数背后的逻辑,应用适当的小时费率C++ 需要帮助获得无效代码工作,并支付总工资吗,c++,visual-c++,codeblocks,c++builder,C++,Visual C++,Codeblocks,C++builder,我需要以下代码帮助更正错误。它的主要功能是接收用户工作小时数,然后根据工作小时数背后的逻辑,应用适当的小时费率 #include <iostream> #include <iomanip> using namespace std; //function prototype void getGrossPay(int regular, int &timeAndHalf, int &doubl
#include <iostream>
#include <iomanip>
using namespace std;
//function prototype
void getGrossPay(int regular,
int &timeAndHalf,
int &doubleTime);
int main()
{ //variables
const int REG_RATE = 10;
const int TIME_HALF = 15;
const int DOUB_TIME = 20;
int hoursWorked = 0;
cout << "Please enter your hours worked(press -1 to quit): ";
cin >> hoursWorked;
getGrossPay(regular, timeAndHalf, doubleTime);
while (hoursWorked != -1);
{
if(hoursWorked >=1 && hoursWorked <=37)
{
getGrossPay(regular);
cout << "Your gross pay is: $ (press -1 to exit)" << regular << endl;
cout << "Please enter your hours worked(press -1 to quit): ";
cin >> hoursWorked;
}
else
if (hoursWorked >=38 && hoursWorked <=50)
{
getGrossPay(timeAndHalf);
cout << "your gross pay is: $(press -1 to exit)" << timeAndHalf << endl;
cout << "Please enter your hours worked(press -1 to quit): ";
cin >> hoursWorked;
}
else
if (hoursWorked >=50)
{
getGrossPay(doubleTime);
cout << "your gross pay is: $(press -1 to exit)" << doubleTime << endl;
cout << "Please enter your hours worked(press -1 to quit): ";
cin >> hoursWorked;
}//end if
}//end while
}// end of main function
//****function definitions*****
void getGrossPay(int regular,
int &timeAndHalf,int &doubleTime)
{
regular = hoursWorked * REG_RATE;
timeAndHalf = hoursWorked * TIME_HALF;
doubleTime = hoursWorked * DOUB_TIME;
} // end getGrossPay function
int main()
{//变量
cout << "Please enter your hours worked(press -1 to quit): " << endl;
cin >> hoursWorked;
while (hoursWorked != -1);
{
if(hoursWorked >=1 && hoursWorked <=37)
{
getGrossPay(regular, timeAndHalf, doubleTime);
cout << "Your gross pay is: $ (press -1 to exit)" << regular << endl;
cout << "Please enter your hours worked(press -1 to quit): " << endl;
cin >> hoursWorked;
}
else
if (hoursWorked >=38 && hoursWorked <=50)
{
getGrossPay(regular, timeAndHalf, doubleTime);
cout << "your gross pay is: $(press -1 to exit)" << timeAndHalf << endl;
cout << "Please enter your hours worked(press -1 to quit): " << endl;
cin >> hoursWorked;
}
else
if (hoursWorked >=50)
{
getGrossPay(regular, timeAndHalf, doubleTime);
cout << "your gross pay is: $(press -1 to exit)" << doubleTime << endl;
cout << "Please enter your hours worked(press -1 to quit): " << endl;
cin >> hoursWorked;
}//end if
}//end while
getGrossPay()
根据定义用3个参数声明。但是,在main()
函数中有3个实例,例如:
getGrossPay(regular);
只有一个参数被传递给函数。您需要重新处理函数,因为代码中有许多关于getGrossPay()
的逻辑错误
此外,您没有在main()
中声明regular
,而是将其传递给getGrossPay()
函数
同样,您在
main()
函数中声明了DOUB\u TIME
、REG\u RATE
和TIME\u HALF
;因此,它在getGrossPay()中是不可访问的
函数。如果GetGrossPay是一个带有三个参数的原型函数,那么如果不给它三个参数,它将无法工作。我建议修改您的函数。REG\u RATE
,DOUB\u TIME
,TIME\u HALF
仅在main()中声明
函数;它们对于getGrossPay()
是不可访问的。有关代码中的其他错误,请参阅下面的答案。
//****function definitions*****
void getGrossPay(int regular,
int &timeAndHalf,int &doubleTime)
{
regular = hoursWorked * REG_RATE;
timeAndHalf = hoursWorked * TIME_HALF;
doubleTime = hoursWorked * DOUB_TIME;
} // end getGrossPay function
getGrossPay(regular);