需要帮助使 VOID 代码与总工资一起工作
Need help getting VOID code working w/ gross pay
我需要帮助纠正以下代码的错误。它的主要功能是接收用户的工作小时数,然后根据工作小时数背后的逻辑,应用适当的小时费率。
#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
是的,这是给一堂课的。不,我不想要答案。
可疑问题:
- 我的空白语法组织错误
- 我的 while 语句未正确使用
- 我的变量被非法从 void 函数调用
任何和所有帮助让我走上正轨的帮助都是 100% 赞赏的。
编辑:
所以这段代码"修复"让我得到一个基本上冻结的可执行文件:
void getGrossPay(int regular, int &timeAndHalf, int 和 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
如果 GetGrossPay 被原型化为具有三个参数的函数,那么如果不给它三个参数,它将无法工作。我建议修改你的函数。
根据
定义,getGrossPay()
是用 3 个参数声明的。但是,在 main()
函数中的 3 个实例中,例如:
getGrossPay(regular);
只有一个参数传递给函数。您需要重新处理函数,因为代码中有许多关于getGrossPay()
的逻辑错误。
此外,您没有在 main()
中声明regular
,而是将其传递给 getGrossPay()
函数。
此外,您已经在main()
函数中声明了DOUB_TIME
、REG_RATE
和TIME_HALF
;因此,它在getGrossPay()
函数中无法访问。
相关文章:
- 如何使我的 sizeof sum 结构与空参数包一起工作
- SFINAE:它如何与派生类一起工作?
- std::remove() 按预期处理文字,但不能与取消引用的迭代器一起工作
- 尝试让条形码扫描仪与Arduino一起工作
- 从书本中学习C++无法使该程序与类一起工作
- 让类与运算符一起工作更简单的方法
- 如何使lambda与std::nullopt一起工作
- 当我使用长整型时,我的代码不起作用,它与 int 一起工作得很好
- 返回对象如何与分配运算符一起工作
- GLM :: perspective()和glm :: lookat()一起工作
- SFML OpenGL:如何同时与他们一起工作
- 使QTConcurrent ::映射与Lambdas一起工作
- 如何与C 字符串中的非ASCII字符一起工作
- 我如何适应擦除式习惯与矢量元组一起工作
- 需要帮助使 VOID 代码与总工资一起工作
- 我怎样才能让这个刽子手代码与 wxDev-C++ 一起工作
- Googletest 在 bazel test 中永远不会失败(在它应该失败的地方),但与 cmake & clion 一起工作
- 常量变量初始化仅与成员初始化列表一起工作
- feal_ptr与unique_ptr一起工作
- OpenGL Ping Pong可与一张通行证一起工作,而不是两个通行证