2017-04-06 4 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 

はい、これはクラス用です。いいえ、私は答えがほしくない。

疑い問題:

  • マイ無効な構文文が適切に私の変数は違法void関数

任意およびすべてから呼び出されている

  • を利用イマイチながら誤っ
  • 私に編成されています私を正しい軌道に乗せる援助は100%高く評価されています。

    EDIT:

    だから、 "修正" このコードは基本的にフリーズし、実行可能に私を取得します。

    無効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'は' main() '関数内でのみ宣言されています。彼らは 'getGrossPay()'にアクセスできません。コードの他の不具合については、私の答えを見てください。 –

    答えて

    0

    getGrossPay()を定義することによって3つのパラメータで宣言されています。しかし、のようなあなたのmain()機能では3例、で:

    getGrossPay(regular); 
    

    だけのパラメータは、あなたの関数に渡されます。あなたのコードにgetGrossPay()に関する多くの論理エラーがあるので、あなたの関数を再処理する必要があります。

    main()に宣言していませんが、getGrossPay()関数に渡します。

    また、あなたはあなたのmain()関数内DOUB_TIMEREG_RATETIME_HALFを宣言しました。したがって、getGrossPay()関数ではアクセスできません。

    0

    GetGrossPayが3つのパラメータを持つ関数としてプロトタイプ化されている場合、3つの引数を指定しなければ機能しません。あなたの機能を変更することをお勧めします。

    関連する問題