A mobile manufacturing company pays its employees as follows: - C Programming

A mobile manufacturing company pays its employees as follows: 

  1.  Team leaders (fixed fortnightly salary) 
  2.  Sales workers ($500 plus 6.5% of their gross fortnightly sales) 
  3.  Pieceworkers (fixed amount of money per item for each of the items they produce, each piece worker in this company works on only 1 type of item) 
  4.  Hourly workers (fixed hourly wage for up to the first 60 hours they work and "time-and a-half" i.e., 1.5 times their hourly wage, for overtime hours worked)  
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: 
  •  Code 1: Team leaders 
  •  Code 2: Sales workers 
  •  Code 3: Pieceworkers 
  •  Code 4: Hourly workers 

There will be an undetermined number of entries into the payroll. Use a switch to compute each employee's pay based on that employee's pay code. Within the switch, prompt the user (i.e., the payroll clerk) to enter the appropriate facts your program needs to calculate each employee's pay based on that employee's pay code. Print each pay value and when done with the entries, print total amount of payroll.

Sample Run:
Enter employee's number code (-1 to end): 4 
Enter hourly worker's pay rate: 10 
Enter the number of hours worked: 35 
fortnightly pay is: 350.00
 
Enter employee's number code (-1 to end): 4 
Enter hourly worker's pay rate: 15.5 
Enter the number of hours worked: 100 
fortnightly pay is: 1860
 
Enter employee's number code (-1 to end): 4 
Enter hourly worker's pay rate: 10 
Enter the number of hours worked: 40 
fortnightly pay is: 400.00
 
Enter employee's number code (-1 to end): 1 
Enter the Team leaders’s pay rate: 576.90 
fortnightly pay is: 576.90
 
Enter employee's number code (-1 to end): 2 
Enter Sales employee's gross weekly sales: 
1091.45 fortnightly pay is: 570.94
 
Enter employee's number code (-1 to end): 3 
Enter the number of pieces completed: 200 
Enter the employee's per piece pay rate: 0.5 
fortnightly pay is: 100
 
Enter employee's number code (-1 to end): 8 
You have entered an invalid code.
 
Enter employee's number code (-1 to end): 9 
You have entered an invalid code.
 
Enter employee's number code (-1 to end): 3 
Enter the number of pieces completed: 100 
Enter the employee's per piece pay rate: 
2.75 fortnightly pay is: 275.00
 
Enter employee's number code (-1 to end): 
-1 
The total payroll for the fortnight 
is:4132.84

Answer:
#include 

double totalPayroll = 0;

void teamLeader()
{

    double payRate = 0;

    printf("Enter the Team leaders's pay rate: ");
    scanf("%lf", &payRate);

    totalPayroll += payRate;

    printf("fortnightly pay is: %.2lf\n\n",payRate);

}
void salesWorkers()
{

    double weeklySales = 0,payment = 0;

    printf("Enter Sales employee's gross weekly sales: ");
    scanf("%lf", &weeklySales);

    payment = weeklySales * (6.5/100) + 500;

    totalPayroll += payment;

    printf("fortnightly pay is: %.2lf\n\n", payment);

}
void pieceWorkers()
{

    double numPcs = 0, payRate = 0, payment = 0;

    printf("Enter the number of pieces completed: ");
    scanf("%lf", &numPcs);

    printf("Enter the employee's per piece pay rate: ");
    scanf("%lf", &payRate);

    payment = numPcs * payRate;
    totalPayroll += payment;

    printf("fortnightly pay is: %.2lf\n\n", payment);
}

void hourlyWorkers()
{

    double hourlyRate = 0, numberHours = 0, payment = 0;

    printf("Enter hourly worker's pay rate: ");
    scanf("%lf", &hourlyRate);
    printf("Enter the number of hours worked: ");
    scanf("%lf", &numberHours);

    if( numberHours > 60)
    {
        payment = (numberHours - 60) *  1.5 * hourlyRate + 60 * hourlyRate;
    }
    else
    {
        payment = numberHours * hourlyRate;
    }
    totalPayroll += payment;

    printf("fortnightly pay is: %.2lf\n\n",payment);


}

void getChoice()
{
    int choice;

    printf("Enter employee's number code (-1 to end): ");
    scanf("%d",&choice);

    switch(choice)
    {
    case 1 :
        teamLeader();
        getChoice();
        break;
    case 2 :
        salesWorkers();
        getChoice();
        break;
    case 3 :
        pieceWorkers();
        getChoice();
        break;
    case 4 :
        hourlyWorkers();
        getChoice();
        break;
    case -1:
        printf("The total payroll for the fortnight is %.2lf\n\n", totalPayroll);
        break;
    default:
        printf("You have entered an invalid code.\n\n");
        getChoice();
    }

}

int main()
{

    getChoice();


    return 0;
}


Comments

Popular posts from this blog

Implement a class named RandNum. The class should have a 5x5 2D array of 25 integers. The constructor should use the random() function to generate a random number in the range of 1 to 100 for each element in the array. Implement a method to calculate the minimum, maximum and average of the 25 values. Implement a method to display the values of the array, minimum, maximum and average of the 25 values.