我正在为只有6个推销员的汽车公司开发一个程序。该程序将要求用户输入每个销售人员的姓名和他的月薪,输入他在一个月内销售的汽车数量,以及每辆汽车的品牌和价格。该程序将显示每个销售员的月收入(工资+佣金),销售员的平均月收入,收入最高的销售员的姓名(和收入),销售员的姓名(和收入)最低收入,每个品牌销售的汽车数量以及最受欢迎的品牌 。在C++中传递函数之间的值
我一直在传递来自Salesman1()和Salesman2()的totalCommission的值。另一个问题是,我不知道是否可以将CIN字符串转换为名为SalesmanName的数组。这是我迄今为止所做的。
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;
}
如果这不是真正的兼职,为什么不使用Java或C#? – 2014-09-21 06:42:15
编译所有警告和调试信息('g ++ -Wall -g')。然后**使用调试器**('gdb')。并利用C++功能!你可以用'>>'或[getline](http://www.cplusplus.com/reference/string/string/getline/)读取C++'std :: string'。花点时间阅读[C++参考](http://www.cplusplus.com/reference/) – 2014-09-21 06:43:35
@KickButtowski,我不知道Java或C#。我只知道C++。我是新手。 – 2014-09-21 06:44:04