2016-09-15 2 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] 하나 배열 요소가 아닌 전체 배열에 대한 일치하는 기능을 말하는없는 에러가 발생합니까; 배열 대신 intdouble을 전달하려고합니다. 함수가 이미 전체 배열을 처리하기 때문에

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

당신은 루프를 필요로하지 않으며, 기능 :

는 배열의 이름이 hours, payRatewages 때문에,이 같은 함수를 호출 아무것도 반환하지 않습니다 (결과는 wages에 저장 됨).

(그리고 보조 노트로, 그 변수는 글로벌하지, main 로컬이어야합니다.)