A company pays its employees as managers (who recieve a fixed weekly salary), hourly workers (who recieve 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 workes (who recieve $250 plus 5.7% of their gross weekly sales), or pieceworkers (who recieve a fixed amount of money per item for each of hte items they produce-each pieceworker in this company works on only one type of item). Can anyone help me out with the source code to calculate the weekly pay for each employee. there is no number of employees in advance. each type of employee has its own pay code managers have paycode , hourly workers have pay code 2, commission workers have code 3 and pieceworkers have code 4.I need to use a switch to compute each employees pay according to that employees paycode. within the switch, i need to prompt the user (i.e...the payroll clerk) to enter the appropriate facts it needs to calculate each employee's pay according to that employee's paycode.

#include <stdio.h>
int main()
{
	int employeenum;
	int name;
int paytype;
int paytype1;
int paytype2;
int paytype3;
int paytype4;
int salary;
int overtimehr;
int commsale;
int hrrate;
int commpay= 250;
float commrate=0.057;
int numitems;
int payperitem;
float overtimerate=1.5;
printf("manager=1,workers=2,commison workers=3,piece workers=4\n");
printf("Enter employee name\n");
scanf("%d",&name);
printf("Enter Employee number\n");
scanf("%d",&employeenum);
printf("Enter payrate or salary\n");
scanf("%d",&salary);
printf("Enter hourly rate for worker\n");
scanf("%d",&hrrate);
printf("Enter total sales made by the paycode three worker\n");
scanf("%d",&commsale);
printf("Enter number of items produced by the paycode four worker\n");
scanf("%d",&numitems);
printf("Enter pay per each item\n");
scanf("%d",&payperitem);

switch(paytype) 
{
case 1:
paytype= salary;
break;
case 2:
paytype= (40* hrrate)+ (overtimehr * overtimerate) ;
break;
case 3:
paytype = commpay+(commsale * commrate );
break;
case 4:
paytype = payperitem * numitems ;
break;
}
}

can you guys help me out tell me whats wrong if its correxct and how to improve it.

you have the right idea so far. your switch is (correctly) operating as conditional on the "paytype"

but why, within each case, are you trying to assign values to the "paytype" variable? each case should be asking for the type of payment that is appropriate for the pay type, and then calculating the weekly pay based on the repsonses and according to the paytype.

for instance, in "case 1:" you would prompt the user to input "yearly salary"... then simply divide that number by 52, and the answer is "weekly pay"

case 1:
printf("enter yearly salary in dollars: $");
scanf("%f",salary);
weeklypay = salary / 52.0;
break;

follow this patter with the rest of the cases (you might prompt for hourly rate, and number of hours ... or piece rate and number of pieces ... etc) then after you close the switch() statement, you can print what the worker receives. remember to format it in such a way that it looks sensible.

printf("this persons weekly check is $ %4.2f \n",weeklypay);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.