2014-09-21 3 views
-2

저는 세일즈맨이 6 명 밖에없는 자동차 회사 용 프로그램을 만들고 있습니다. 이 프로그램은 사용자에게 각 영업 사원의 이름과 월급을 입력하고 한 달에 판매 한 차량 수와 각 차량의 브랜드 및 가격을 입력하도록 요청합니다. 이 프로그램은 각 영업 사원의 월 소득 (급여 + 수수료), 영업 사원의 평균 월 소득, 최고 소득을 가진 영업 사원의 이름 (수입), 영업 사원의 이름 최저 수입, 각 브랜드별로 판매 된 자동차 수 및 가장 인기있는 브랜드입니다.C++의 함수 사이에 값 전달

Salesman1() 및 Salesman2()에서 totalCommission 값을 전달하는 데 막혔습니다. 또 다른 문제는, 내가 SalesmanName이라는 배열에 문자열을 CIN 할 수 있는지 여부를 모르겠습니다. 여기까지 내가 한 일이있다. 수행

return totalCommission; 

main()에서 :

int allCommissions = 0; 

을 다음 루프에서 당신은 수행합니다 SalesmanN() 기능에

int main() 
{  
int cycle=1; 
int SalesMan1(),SalesMan2(); 


do 
{ 
    switch(cycle) 
    { 
     case 1: SalesMan1(); cycle++; break; 
     case 2: SalesMan2(); cycle++; break; 
     /*case 3: SalesMan3(); cycle++; break; 
     case 4: SalesMan4(); cycle++; break; 
     case 5: SalesMan5(); cycle++; break; 
     case 6: SalesMan6(); cycle++; break;*/ 
     default: cout<<"Printing out reports"<<endl; 
       system("\npause"); 
    } 
}while(cycle<=6); 

return 0;                        

} 

int SalesMan1() 
{ 
    char NameOne[40]; 
    int numCar=1,carSold,carType,audiSold=0,bmwSold=0,mbenzSold=0; 
    double salary,carPrize,commission,totalCommission,allMonthlyIncome; 

    cout<<"Name of 1st Salesman:"<<endl; 
    cin.getline(NameOne,39); 

    cout<<"\nMonthly Salary: RM"; 
    cin>>salary; 

    cout<<"\nNumber of car sold in a month: "; 
    cin>>carSold; 
    system("CLS"); 

    do{ 
     cout<<"\nEnter type of car sold as below: "<<endl; 
     cout<<"\n1-Audi"<<endl; 
     cout<<"2-BMW"<<endl; 
     cout<<"3-Mercedes Benz"<<endl; 
     cout<<"\nCar Type:"; 
     cin>>carType; 

     switch(carType) 
     { 
     case 1: 
      cout<<"\nEnter the price sold: RM"; 
      cin>>carPrize; 
      commission=0.02*carPrize; 
      totalCommission+=commission; 
      audiSold++; 
      system("CLS"); 
      break; 

     case 2: 
      cout<<"\nEnter the price sold: RM"; 
      cin>>carPrize; 
      commission=0.02*carPrize; 
      totalCommission+=commission; 
      bmwSold++; 
      system("CLS"); 
      break; 

     case 3: 
      cout<<"\nEnter the price sold: RM"; 
      cin>>carPrize; 
      commission=0.035*carPrize; 
      totalCommission+=commission; 
      mbenzSold++; 
      system("CLS"); 
      break; 

     default : 
      cout<<"\nNot available!"<<endl; 
      system("pause"); 
      return 1; 
     } 
     numCar++; 
    }while(numCar<=carSold); 

    allMonthlyIncome=allMonthlyIncome+totalCommission+salary; 

} 

int SalesMan2() 
{ 
    char NameTwo[40]; 
    int numCar=1,carSold,carType,audiSold=0,bmwSold=0,mbenzSold=0; 
    double salary,carPrize,commission,totalCommission,allMonthlyIncome; 

    cout<<"Name of 2nd Salesman"<<endl; 
    cin.getline(NameTwo,39); 

    cout<<"\nMonthly salary: RM"; 
    cin>>salary; 

    cout<<"\nNumber of car sold in a month: "; 
    cin>>carSold; 
    system("CLS"); 

    do{ 
     cout<<"\nEnter type of car sold as below: "<<endl; 
     cout<<"\n1-Audi"<<endl; 
     cout<<"2-BMW"<<endl; 
     cout<<"3-Mercedes Benz"<<endl; 
     cout<<"\nCar Type:"; 
     cin>>carType; 

     switch(carType) 
     { 
     case 1: 
      cout<<"\nEnter the price sold: RM"; 
      cin>>carPrize; 
      commission=0.02*carPrize; 
      totalCommission+=commission; 
      audiSold++; 
      system("CLS"); 
      break; 

     case 2: 
      cout<<"\nEnter the price sold: RM"; 
      cin>>carPrize; 
      commission=0.02*carPrize; 
      totalCommission+=commission; 
      bmwSold++; 
      system("CLS"); 
      break; 

     case 3: 
      cout<<"\nEnter the price sold: RM"; 
      cin>>carPrize; 
      commission=0.035*carPrize; 
      totalCommission+=commission; 
      mbenzSold++; 
      system("CLS"); 
      break; 

     default : 
      cout<<"\nNot available!"<<endl; 
      system("pause"); 
      return 1; 
    } 
    numCar++; 
    }while(numCar<=carSold); 

    allMonthlyIncome=allMonthlyIncome+totalCommission+salary; 
} 
+1

이것이 정말로 homwork가 아니면 Java 또는 C#을 사용하지 않으시겠습니까? –

+0

모든 경고와 디버그 정보 ('g ++ -Wall -g')로 컴파일하십시오. 그런 다음 ** 디버거 ** ('gdb')를 사용하십시오. C++ 기능을 활용하십시오! '>>'또는 [getline] (http://www.cplusplus.com/reference/string/string/getline/)을 사용하여 C++'std :: string'을 읽을 수 있습니다. [C++ 참고서] (http://www.cplusplus.com/reference/)를 읽으십시오. –

+0

@KickButtowski, Java 또는 C#을 모른다. 나는 C++ 만 알고있다. 그리고 나는 그것에 익숙하지 않습니다. –

답변

2

, 그것을 종료

case 1: allCommissions += SalesMan1(); cycle++; break; 
+0

감사! 정말 도움이됩니다. –

0

당신은 CIN을 할 수 있습니다. 모든 문자 배열이지만 CIN이 공백에 대한 입력을 제한하므로 이름에는 적합하지 않습니다. SalesmanName에는 공백이 없습니다. 만약 이름으로 "XYZ ABC"를 입력하면

char arr[1000]; 
cin`>>arr; 

다음 "ABC"가 입력 스트림 래미안 반면 []은 "XYZ"를 저장하는 것이다, 언.

이 질문에 대해서는 Salesman 클래스를 만들면 각 Salesman에 필요한 모든 기능과 데이터를 캡슐화 할 수 있습니다. 회사는 6 명 밖에 없으므로 세일즈맨 클래스의 6 가지 객체 배열을 만들 수 있습니다. 그래서 특정 Salesman의 커미션을 SalesMan [i] .getCommission()으로 참조 할 수 있습니다. 또한 수업은 나중에 더 많은 수의 직원에게 확대 될 것입니다.