1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice


Discussion in 'C' started by onefootswill, Nov 19, 2007.

  1. onefootswill

    onefootswill New Member

    I have no idea if C newbies are welcome here, so I have a novice problem which I cannot figure out. This is just an exercise from a book. There are two problems:

    1st: as per following screenshot, the menu is displayed twice, following the 1st operation.


    2nd: the calculation is wrong for hourly workers who worked more than 40 hours. They should be paid 1.5 times the hourly rate for each hour over 40 hours.

    The code is:
    #include <stdio.h>
    int main()
    	char ch;
    	float weeklyPay;
    	printf("Select the relevant employee type (press ctrl-z to exit): \n");
    	printf("m (manager)\n");
    	printf("h (hourly workers)\n");
    	printf("c (commission workers)\n");
    	printf("p (piece-workers)\n");
    	ch = getchar();
    	while(ch != EOF)
    		case 'm': printf("Enter the manager's salary: \n");
    			int salary; 
    				scanf("%d", &salary);
    				weeklyPay = (float)salary / 52;
    				printf("Manager's weekly pay is: $%.2f", weeklyPay);
    		case 'h': printf("Enter the number of hours worked: ");
    			int hours = 0;
    			float hourlyRate = 0;
    			scanf("%i", &hours);
    			printf("Enter the hourly rate: ");
    			scanf("%f", &hourlyRate);
    			if(hours < 41) 
    				weeklyPay = (float)hours * hourlyRate;
    				weeklyPay = (float)(40 * hourlyRate) + ((40 - hours) * 1.5 * hourlyRate);
    			printf("Hourly worker's weekly pay was $%.2f\n\n", weeklyPay);
    		printf("Select the relevant employee type (press ctrl-z to exit): \n");
    		printf("\tm (manager)\n");
    		printf("\th (hourly workers)\n");
    		printf("\tc (commission workers)\n");
    		printf("\tp (piece-workers)\n");
    		ch = getchar();
    	return 0;
  2. shabbir

    shabbir Administrator Staff Member

    You have submitted it as an Article and I have moved to the forum for discussion.
  3. onefootswill

    onefootswill New Member

    This is now solved. Thanks.

Share This Page