我需要帮助纠正错误,使用以下代码。它的主要功能是接收用户工作小时数,然后根据工作小时数后面的逻辑,应用适当的小时费率。
#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
是的,这是一堂课。不,我不想要答案。
疑似问题:
任何帮助我走上正确轨道的帮助都是100%的赞赏。
编辑:
所以这段代码“修复”让我得到一个基本冻结的可执行文件:
void getGrossPay(int regular, int&amp; timeAndHalf, int&amp; doubleTime);
const int REG_RATE = 10;
const int TIME_HALF = 15;
const int DOUB_TIME = 20;
int hoursWorked = 0;
int regular = 0;
int timeAndHalf = 0;
int doubleTime = 0;
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
} //主要功能结束
//****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
答案 0 :(得分:0)
getGrossPay()
被声明为3个参数。但是,在main()
函数中有3个实例,例如:
getGrossPay(regular);
仅将一个参数传递给您的函数。您需要重新运行函数,因为代码中有getGrossPay()
的许多逻辑错误。
另外,您尚未在regular
中声明main()
,而是将其传递给getGrossPay()
函数。
,您已宣布DOUB_TIME
,REG_RATE
和TIME_HALF
您的{{ 1}}功能;因此,main()
函数无法访问它。
答案 1 :(得分:0)
如果将GetGrossPay原型化为具有三个参数的函数,则在不给它三个参数的情况下它将无法工作。我建议修改你的功能。