Salesperson at McHenry Tool corporation are given a monthly commission check. Use array method to compute a salesperson’s monthly commission for several number of salesperson.
Input =
1. name of the salesperson
2. commission rate
3. gross monthly sales
The output should be arranged in the way so that each salesperson’s commission should be printed next to his or her name.
Output =
1. Total monthly commission (summed across all salespersons)
2. The average commission per salesperson
Error Checking: Any names of sales persons who have invalid data should be printed out separately. Data are invalid if the commission rate is not between 0.01 and 0.50 or if the gross monthly sales figure is negative.
#include<iostream>
#include<string>
usingnamespace std;
int main()
{
int x, y, i;
string name[10];
double sales[10], rate[10], com[10], average[10], total1, total2;
// First of all initialise all variables and arrays
total1=0.0;
total2=0.0;
for(x=0;x<10;x++){
sales[x]=0.0;
rate[x]=0.0;
com[x]=0.0;
}
cout << "Enter Number : ";
cin >> i;
for (x = 0; x<i; x++) // array index starts from 0 and ends at i-1
{
cout << "Name [" << x << "] = ";
cin >> name[x];
cout << "Rate [" << x << "] = ";
cin >> rate[x] ;
// check user given value is okay or not
if (( rate[x]>=0.01) && (rate[x]<=0.5))
{
// do nothing
}else{
cout<< "The rate is not between 0.01 and 0.5, wrong rate please reenter\n";
cin >> rate[x] ;
}
cout << "Sales [" << x << "] = ";
cin >> sales[x];
// check the user given value is okay or not
if(sales[x]<0){
cout<< "Sales data is wrong, it cannot be negative, please reenter\n";
cin >> sales[x];
}
// We have given one chance to user, if he has done wrong we will give his commision 0
if (( rate[x]>=0.01) && (rate[x]<= 0.5) || (sales[x] >= 0))
{
com[x] = sales[x] * rate[x];
total1 = total1 + com[x];
}
else
{
cout<<"Again you have provided wrong data, your commision is 0\n";
com[x]=0;
sales[x] =0;
}
}//for
// Now we have all the data
cout<<"Total monthly commision is " << total1 << "\n";
cout<<"Average monthly commision is "<<total1/i<<"\n";
cout<< "Each sales person's comssion is given below\n";
for (x = 0; x<i; x++)
{
cout << name[x];
cout << " ";
cout << com[x];
cout << " \n";
}
return 0;
}