2016-09-15 8 views
-4
/************************************************************************************** 
* The program should display each employee number         * 
* ask the user to enter that employee’s hours and pay rate.       * 
* It should then calculate the gross wages for that employee(hours times pay rate) * 
* store them in the wages array.             * 
* After the data has been entered for all the employees,       * 
* the program should display each employee’s identification number and gross wages. * 
**************************************************************************************/ 

#include <cstdlib> 
#include <iostream> 
#include <iomanip> 

using namespace std; 


const int Num_Employees = 7; // global constant of # of employees 

int empId[Num_Employees] = {5658846, 4520125, 785122, 877541, 8451277, 1302850, 7580489}; // array of Employee ID #'s 
int hours[7];  // empty array of 7 possible values for employee hours 
double payRate[7]; // empty array of 7 possible values for employee pay rates 
double wages[7]; // empty array of 7 possible values for employees wages (hours * pay rate) 

void calcGrossWages(int[], double[], double[]); // calculate gross wages prototype 



int main() { 


    // Employees 
    for(int i= 0; i< Num_Employees; i++) { 

     cout << "Your ID is: " << "" << empId[i] << endl; // displays each employee # 

     cout << "How many hours did you work?"; 

     cin >> hours[i]; 



     cout << "What was your payRate?" << endl; 

     cout <<"$"; 

     cin >> payRate[i]; 
    } 

     /*Calculate the gross wages*/ 

    for(int i = 0; i < Num_Employees; i++) { 

     wages[i] = calcGrossWages(hours[i], payRate[i], wages[i]); 


    } 

    } 



//****************************************************************************** 
//* Definition of calcGrossWages function          * 
//* This function calculates the employees Wages        * 
//* Wages are calculated by the # of hours worked by each employee    * 
//* multiplied by their enter pay rate           * 
// ***************************************************************************** 

void calcGrossWages(int hours[], double payRate[], double wages[]) 
{ 
    for (int i= 0; i< Num_Employees; i++) { 

      wages[i] = hours[i] * payRate[i]; 

    } 





} 

質問:正しく関数にパラメータとして配列を渡す方法C++ /エラー:calcGrossWages(への呼び出しに該当する機能)

、一つは空の配列に値を入力することができるようにすること?

は、なぜ私は、コール「calcGrossWages」

+0

'calcGrossWages呼び出すため(時間[i]は、payRate [i]は、賃金は、[I]);'と呼び出し普通 'double'引数よりもむしろアレイ。 –

答えて

0

あなただけの配列の要素を渡すと、メインループを必要としないcalcGrossWagesの代わりに配列を渡す必要がありますcalcGrossWages

/******************************************************************************** ****** 
* The program should display each employee number         * 
* ask the user to enter that employee’s hours and pay  rate.       * 
* It should then calculate the gross wages for that employee(hours times pay rate) * 
* store them in the wages  array.             * 
* After the data has been entered for all the  employees,       * 
* the program should display each employee’s identification number and gross wages. * 
******************************************************************************** ******/ 

#include <cstdlib> 
#include <iostream> 
#include <iomanip> 

using namespace std; 


const int Num_Employees = 7; // global constant of # of employees 

int empId[Num_Employees] = {5658846, 4520125, 785122, 877541, 8451277, 1302850,  7580489}; // array of Employee ID #'s 
int hours[7];  // empty array of 7 possible values for employee hours 
double payRate[7]; // empty array of 7 possible values for employee pay rates 
double wages[7]; // empty array of 7 possible values for employees wages ( hours * pay rate) 

void calcGrossWages(int[], double[], double[]); // calculate gross wages prototype 



int main() { 


    // Employees 
    for(int i= 0; i< Num_Employees; i++) { 

     cout << "Your ID is: " << "" << empId[i] << endl; // displays each employee # 

     cout << "How many hours did you work?"; 

     cin >> hours[i]; 



     cout << "What was your payRate?" << endl; 

     cout <<"$"; 

     cin >> payRate[i]; 
    } 

     /*Calculate the gross wages*/ 

    calcGrossWages(hours, payRate, wages); 

    } 




//****************************************************************************** 
//* Definition of calcGrossWages function          * 
//* This function calculates the employees Wages        * 
//* Wages are calculated by the # of hours worked by each employee    * 
//* multiplied by their enter pay rate           * 
// ***************************************************************************** 

void calcGrossWages(int hours[], double payRate[], double wages[]) 
{ 
    for (int i= 0; i< Num_Employees; i++) { 

      wages[i] = hours[i] * payRate[i]; 

    } 





} 
+0

ありがとう私は関数を呼び出すためにforループを実行する必要があると思った理由を知りません。 –

0

array[i]ある1つの配列要素ではなく、配列全体に該当する機能を言っていないエラーが出るん。配列の代わりにintdoubleを渡そうとしています。関数は、すでに全体の配列を処理しますので、

/*Calculate the gross wages*/ 
calcGrossWages(hours, payRate, wages) 

あなたはループを必要としない、と機能:

は、配列の名前はhourspayRate、およびwagesなので、あなたはこのような関数を呼び出します何も返されません(結果はwagesに格納されます)。

(そして、サイドノートとして、これらの変数はグローバル、mainに対してローカルではないはずです。)

関連する問題