2017-04-06 47 views
0

我需要幫助糾正與下面的代碼錯誤。其主要功能是接收用戶工作小時,然後根據邏輯工作的小時數,適用適當的小時費率。需要幫助獲取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 
+0

[爲什麼「有人可以幫我嗎?」不是真正的問題?](https://meta.stackoverflow.com/q/284236/62576) –

+0

'REG_RATE','DOUB_TIME','TIME_HALF'只聲明__inside__'main()'函數;他們無法訪問'getGrossPay()'。查看我的答案,瞭解代碼中的其他錯誤。 –

回答

0

getGrossPay()的端聲明瞭3個參數的定義。然而,在你的main()功能3個實例,如:

getGrossPay(regular); 

只有一個參數傳遞給你的函數。您需要將代碼中的getGrossPay()的邏輯錯誤重新設置爲您的函數。

另外,您還沒有在main()中聲明regular,但是您將其傳遞給getGrossPay()函數。

此外,聲明瞭DOUB_TIMEREG_RATETIME_HALFmain()功能;因此,在getGrossPay()函數中無法訪問。

0

如果GetGrossPay是一個帶有三個參數的函數原型,那麼在沒有給它三個參數的情況下它將不起作用。我建議修改你的功能。