Click here to Skip to main content
15,173,299 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
/*A company pays its employees as managers (who receive a fixed weekly salary),
hourly workers (who receive a fixed hourly wage for up to the first 40 hours they
work and “time-and-a-half” 1.5 times their hourly wage for overtime hours
worked), commission workers (who receive 250 ETB plus 5.7 percent of their
gross weekly sales), or pieceworkers (who receive a fixed amount of money per
item for each of the items they produce each pieceworker in this company works
on only one type of item). Write a program to compute the weekly pay for each
employee. You do not know the number of employees in advance. Each type of
employee has its own pay-code: Managers have code C1, hourly workers have
code C2, commission workers have code C3 and pieceworkers have code C4.
Use more appropriate selection structure to compute each employee’s pay
according to that employee’s pay-code. The program should prompt the user (i.e.,
the payroll clerk) to enter the appropriate facts your program needs to calculate
each employee’s pay according to that employee’s pay-code. Finally, the
program prints the weekly pay of the employees in tabular format. Also the
program allows the user to search for specific record.*\

What I have tried:

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
string name[100], type, suffix, srch;
int fixed[100], work[100], price[100], coun;
char quit = '1';
int regular, par, length, srch_coun;

do{
        first:
    cout<< "Type of Worker (Worker Code): \n C1 - For the Manager\n C2 - For Hourly Work Plus Overtime\n C3 - For Salesman \n C4 - For Pieceworkers)\n ";
    cout<< "Please Enter the work area code you want to access: ";
    cin>>type;
    if (coun + 1 ==1)
        suffix="st";
      else if (coun + 1 ==2)
        suffix="nd";
      else if(coun + 1 ==3)
        suffix="rd";
      else
        suffix="th";
      cout << coun + 1<<suffix<<" Employee's Data "<< endl;
if (type == "C1" || type == "c1"){
    cout << "Employee(Manager's) Name: ";
    getline(cin >> ws, name[coun]);
    cout << "Income of the manager: ";
    cin >> fixed[coun];
} else if (type == "C2" || type == "c2") {
    cout << "Employee(Hourly worker's) Name: ";
    getline(cin >> ws, name[coun]);
    cout << "Hourly Pay: ";
    cin >> fixed[coun];
    cout << "Hourly Worked: ";
    cin >> work[coun];
    if(work[coun]<=40){   //regular hours
       fixed[coun] = fixed[coun]*work[coun];
    } else if(work[coun]>40){     // have Overtime
    regular=40*fixed[coun];
    par=(work[coun]-40) * (1.5*fixed[coun]);
    fixed[coun] = regular + par;
    }
} else if (type == "C3" || type == "c3") {
    cout << "Employee(Commission worker's) Name: ";
    getline(cin >> ws, name[coun]);
    cout << "Number of Sales Made: ";
    cin >> fixed[coun];
    cout << "Average Price of Each Sales: ";
    cin >> price[coun];
    fixed[coun] = 250 + (0.057*fixed[coun]*price[coun]);
} else if (type == "C4" || type == "c4") {
    cout << "Employee(piece worker's) Name: ";
    getline(cin >> ws, name[coun]);
    cout << "Number of Item Produced: ";
    cin >> fixed[coun];
    cout << "Price of One Produced: ";
    cin >> price[coun];
    fixed[coun] = fixed[coun] * price[coun];
} else {
cout << "Enter a Valid Employee Code :| \n";
goto first;
}
    coun++;
    if (name[coun].length() > length)
        length = name[coun].length();
    //DISPLAY OUTPUT
    cout<<"......................................................................................................."<<endl;
cout<<" Employee's Name \t  Weekly Income "<<endl;
    for(int i=0; i<coun; i++){
    cout<<" " <<name[i] << setw(25-(name[i].length()))<<"\t";
    cout<<fixed[i]<<endl;
}
cout<<"......................................................................................................."<<endl;
//QUIT FUNCTION
    cout<<"Press 0 to quit! - To Continue Press Any Button ";
    cin>>quit;

} while(quit!='0');
//SEARCH FUNCTION
cout<<"......................................................................................................."<<endl;
cout<<"Search For Registered Employee...\n";
do{
cout<<"Search: ";
cin>>srch;
for(int i=0; i<coun; i++){
    for(int j=0; j<3; j++){
        if(srch[j]==name[i].at(j)){
         cout<<"......................................................................................................."<<endl;
         cout<<" Employee's Name \t  Weekly Income "<<endl;
         cout<<" " <<name[i] << setw(25-(name[i].length()))<<"\t";
         cout<<fixed[i]<<endl;
         cout<<"......................................................................................................."<<endl;
         break;
        }
    }
}
srch_coun++;
} while (srch_coun<coun);

return 0;
}
Posted
Updated 23-Jun-21 7:41am
Comments
Richard MacCutchan 23-Jun-21 12:10pm
   
What is the question?
OriginalGriff 23-Jun-21 12:25pm
   
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
merano99 23-Jun-21 18:36pm
   
Code has several warning and space for better

1. // missing header
#include <string>
2. // convert string toupper
string type; cin >> type;
for (auto & c : type) c = toupper(c);
2. // conversion problems
par = lround((work[coun] - 40) * 1.5*fixed[coun]); // round
3. // variables not initialised
int coun = 0;

1 solution

We arent a "code for free" service, but I will give you some tips:

tip 1: each point in your assigments is a task, so split the text and write extra code for ever task and comment it
tip 2: use classes (like for employee) and functions (like salary) with parameters
tip 3: use an IDE like Visual Studio and use the debugger
tip 4: write readable code, indention and clear names are for other people reading your code
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900