Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
/* i'm working on a program to compute worker paycode, and the output */
#include <stdio.h>


void instruct (void);
void pause ();

int main()
{
	int paycode, 
	    Manager    = 0,     //Manager
	    HourWorker = 0,     //Hourly Worker
        ComWorker  = 0,     //Commission Worker
	    PieWorker   = 0;     //Piece Worker
 double salary;
	
	instruct ();
	printf("------------------------------------------------------------------------------\n");
	printf("Paycodes (1= Manager, 2= HourlyWorker, 3= CommissionWorker, 4= PieceWorker)\n (-1 To Terminate Program)\n");
	printf("------------------------------------------------------------------------------\n");
	printf("\nEnter Paycode :");
	scanf("%d", paycode);
	
	while (paycode != -1)
	{
		switch(paycode)
		{
			case 1: 
			Manager++;
			printf("Manager Selected\n");
			printf("Enter Weekly Salary: \n");
			scanf("%f", salary);
			printf("Manager's Total Salary is %2f\n", salary);
			break;
			
			case 2: 
			double wage;
			int hours;
			HourWorker++;
			printf("Hourly Worker Selected\n");
			printf("Enter Hourly Salary: \n");
			scanf("%f", wage);
			printf("Enter Total Hours Worked\n");
			scanf("%d", wage);
			
			if(hours <= 40)
				salary = hours * wage;
			else
				salary = 40 * wage + (hours - 40) * wage * 1.5;
			printf("Hourly Worker's Total pay is %2f\n", salary);
			break;
			
			case 3: 
			int sales;
			ComWorker++;
			printf("Commission Worker Selected\n");
			printf("Enter Gross Weekly Sales: \n");
			scanf("%d", sales);
			salary = sales * 0.057 + 250;
			printf("Commission Worker's Total Salary is %2f\n", salary);
			break;
			
			case 4: 
			int pieces, wagePiece;
			PieWorker++;
			printf("Piece Worker Selected\n");
			printf("Enter Number of Pieces: \n");
			scanf("%d", pieces);
			printf("Enter Wage Per Piece: \n");
			scanf("%d", wagePiece);
			salary = pieces * wagePiece;
			printf("Piece Worker's Total Salary is %2f\n", salary);
			break;
		}
	printf("------------------------------------------------------------------------------\n");
	printf("Paycodes (1= Manager, 2= HourlyWorker, 3= CommissionWorker, 4= PieceWorker)\n (-1 To Terminate Program)\n");
	printf("------------------------------------------------------------------------------\n");
	printf("\nEnter Paycode :");
	scanf("%d", paycode);
	}
	
	printf("\t-------------------------------------");
	printf("\n\t| Number of Employees Paid		: ");
	printf("%d,%d,%d,%d", Manager ,HourWorker , ComWorker ,PieWorker);
	printf("\t\t|\n\t| Number of Managers Paid  : %d", Manager);
	printf("\t\t|\n\t| Number of Hourly Workers Paid  : %d", ComWorker);
	printf("\t\t|\n\t| Number of Piece Workers Paid  : %d", PieWorker);
	printf("\t\t|\n\t-------------------------------");
	
	pause();
	return 0;
}	
void instruct(void)
{
	printf("\tThis Program Will Calculate The Weekly Pay For Each \n");
	printf("\temployee, List The Total NUmber Of Employees Paid    \n");
	printf("\tAnd The Total Number Of Managers, Hourly Workers,     \n");
	printf("\tCommission Workers And Piece Workers Paid For The Week. \n");
	
}
void pause()
{
	
	printf("\nPress any key to continue....");
	getch();
	printf("\r");
	printf("   						");
	printf("\r");
	
}
Posted
Updated 9-Nov-15 5:21am
v2
Comments
Jochen Arndt 9-Nov-15 11:24am    
It would be helpful to know when the crash occurs (at which execution step / after which input) and if there is any kind of error message (e.g. segmentation fault).

Please use the green 'Improve question' link to add these information.
achylast 9-Nov-15 11:34am    
Thanks for remind me my mistake, but the compiler won't compile the program. Error at here Error] 'getch' was not declared in this scope. How to solve this?
Jochen Arndt 9-Nov-15 11:46am    
Then you should update your question accordingly (it does not crash but does not compile).

However, the answer depends on the used operating system. With Windows, include conio.h and use _getch() instead (with leading underscore).

You must pass pointers for all scanf() arguments:
double wage;
// Wrong
//scanf("%f", wage);
// Correct
scanf("%f", &wage);
 
Share this answer
 
In addition of Jochen's comments on scanf - you have a copy/paste bug for case 2.

C++
printf("Enter Hourly Salary: \n");
scanf("%f", wage);
printf("Enter Total Hours Worked\n");
scanf("%d", wage);


... should be ...

C++
printf("Enter Hourly Salary: \n");
scanf("%f", &wage);
printf("Enter Total Hours Worked\n");
scanf("%d", &hours);
 
Share this answer
 

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