我需要幫助糾正與下面的代碼錯誤。其主要功能是接收用戶工作小時,然後根據邏輯工作的小時數,適用適當的小時費率。需要幫助獲取VOID代碼工作總薪水
#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語句心不是利用得當
- 我的變量是合法地從虛空功能
任何及所有叫幫助把我放在正確的軌道是100%讚賞。
編輯:
因此,此代碼 「修復」 讓我給凍結基本上是一個可執行文件:
無效getGrossPay(INT定期, 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主() {//變量
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
[爲什麼「有人可以幫我嗎?」不是真正的問題?](https://meta.stackoverflow.com/q/284236/62576) –
'REG_RATE','DOUB_TIME','TIME_HALF'只聲明__inside__'main()'函數;他們無法訪問'getGrossPay()'。查看我的答案,瞭解代碼中的其他錯誤。 –