CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Threaded View

  1. #1
    Join Date
    Aug 2005
    Posts
    22

    please simplify this program coding

    Hi i recently been helped to solve a given problem which is to develop a program to compute the weekly pay for each employees.

    This is the question...

    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" ie. 1.5 time their hourly wage, for overtime hours worked),

     commission workers (who receive a $250 plus 5% of their gross weekly sales), or

     pieceworkers (show receive a fixed amount of money per item for each of the items they produce - each piece worker in this company works on only one type of item). Write a program to compute the weekly pay for each employee.

    The manager asks you to develop a program to compute the weekly pay for each employee, the number of employees paid each week and the total amount paid by the company in salaries that week. The number of employees and hours worked varies from week to week depending on the amount of work to be done. Employees have their own employee number. Each type of employee has its own pay code: Managers have paycode 1, hourly workers have code 2, commission workers have code 3 and pieceworkers have code 4. Use an if-then-else statement (a switch structure is not allowed) to compute each employee's pay based on that employee's pay code. Then, prompt the user (ie the payroll clerk) to enter the appropriate facts your program needs to calculate each employee's pay based on that employee's paycode.

    Sample input/output

    Enter paycode (-1 to end): 1
    Manager selected.
    Enter weekly salary: 2500
    The manager's pay is $2500.00

    Enter paycode (-1 to end): 2
    Hourly worker selected.
    Enter the hourly salary: 10.50
    Enter the total hours worked: 75
    Worker has worked 35.0 overtime hours.
    Workers pay is $971.25

    Enter paycode (-1 to end): 3
    Commission worker selected.
    Enter gross weekly sales: 9000
    Commission Worker's pay is $700

    Enter paycode (-1 to end): 4
    Piece worker selected.
    Enter number of pieces: 200
    Enter wage per piece: 10
    Piece Worker's pay is $2000.00

    Enter paycode (-1 to end): -1

    Number of managers paid: 1
    Number of hourly workers paid: 1
    Number of commission workers paid: 1
    Number of piece workers paid: 1

    Total amount paid in salaries = $6171.25



    I recently been helped but then it's a switch structure (which is not allow)
    this is the code...it work perfectly fine but could someone please help me to solve this problem using an if-then-else statement? preffered to use #include <iostream> and cout << to display output

    this is a working program code using the switch structure......
    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	/* pay code */
    	int payCode;
    
    	/* input cariables */
    	double hourSalary = 0.0;
    	double weekSalary = 0.0;
    	double Sale;
    	int numberPieces;
    	double pieceRate;
    	double hourWork;
    	double otHours;
    	double salaryTemp;
    
    	/* counters  */
    	int salaryWorkers = 0,
    		hourlyWorkers = 0,
    		commWorkers = 0,
    		pieceWorkers = 0;
    
    	/* total accumulator for the entire payroll */
    	double totalPaid = 0.0;
    
    	/* input promt  */
    	char *prompt = "\n\t1 - Manager\n\t2 - Hourly\n\t3 - Commission\n\t4 - Piece Worker\n\t -1 to Exit\n\tEnter Code: ";
    
    
    	/* loop till -1 */
    
    	printf(prompt);
    	scanf("%d", &payCode);
    
    	while (payCode != -1)
    	{
    		switch (payCode)
    		{
    
    		case 1:
    			/* weekly salary, more 0  */
    			while (weekSalary <= 0.0)
    			{
    				printf("Enter weekly salary: ");
    				scanf("%lf", &weekSalary);
    			}
    				++salaryWorkers;
    				printf("The manager's pay is %8.2f \n", weekSalary);
    				totalPaid += weekSalary;
    				break;
    
    		case 2:
    			/*  hourly rate, more than 0 */
    			while (hourSalary <= 0.0)
    			{
    				printf("Enter the hourly salary: ");
    				scanf("%lf", &hourSalary);
    			}
    				++hourlyWorkers;
    				printf("Enter the total hours worked: ");
    				scanf("%lf",&hourWork);
    
    
    			/* over 40 hours  */
    			if (hourWork > 40)
    				{
    					otHours = hourWork - 40;
    					salaryTemp = ((40 * hourSalary) + (1.5 * otHours * hourSalary));
    				}
    				else
    				{
    					salaryTemp = hourWork * hourSalary;
    				}
    
    				totalPaid += salaryTemp;
    				printf("Workers pay is %8.2f \n", salaryTemp);
    				break;
    
    			case 3:
    				++commWorkers;
    				printf("Enter gross weekly sales: ");
    				scanf("%lf",&Sale);
    				salaryTemp = Sale * .05 + 250.0;
    				totalPaid += salaryTemp;
    				printf("Commission Worker's pay is %8.2f \n", salaryTemp);
    				break;
    
    			case 4:
    				++pieceWorkers;
    				printf("Enter number of pieces: ");
    				scanf("%lf",&pieceRate);
    
    				printf("Enter wage per piece: ");
    				scanf("%d",&numberPieces);
    				salaryTemp = pieceRate * numberPieces;
    				printf("Piece Worker's pay is %8.2f \n", salaryTemp);
    				totalPaid += salaryTemp;
    				break;
    
    	default :
              printf("Please enter 1, 2, 3, 4 or -1\n");
              break;
    
    		}
    
    		printf(prompt);
    		scanf( "%d", &payCode );
    	}
    
    	printf("The total paid out this week is $%11.2f \n", totalPaid);
    
    	/* dislay results  */
    	printf("Number of Managers paid: %d\n", salaryWorkers);
    	printf("Number of Hourly Workers paid: %d\n", hourlyWorkers);
    	printf("Number of Commission Workers paid: %d\n", commWorkers);
    	printf("Number of Piece Workers paid: %d\n", pieceWorkers);
    
    	return 0;
    }
    Last edited by Ejaz; August 19th, 2005 at 02:20 PM. Reason: Code tag added

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured