C program to calculate the wage of labor on a daily basis

In this post, we will learn how to create a program in C that will calculate and print the total daily wage of labor. Wage means the salary or money that has to be paid to the worker. Labor is the man who worked for you. The money that has to be paid to the labor will be paid on a daily basis as per the following wage structure:

Hours Worked Rate Applicable
Until the first eight hours 50.00
For the next four hours 10.00 per hour additional
For the next four hours 20.00 per hour additional
For the next four hours 25.00 per hour additional
For the next four hours 40.00 per hour additional

Find and Print Labor Wages in C

The question is: write a program in C to compute the wage of labor working on a daily basis as per the wage structure provided in the above table. And the result should be as follows:

Enter Name of Employee:      XXXXXXXX
Enter total hours worked:    21
Total Wage:                  310

The program given below is the answer to the above question:

#include<stdio.h>
#include<conio.h>
int main()
{
    float initWage=50, hours, tempHour, tempWage, totalWage;
    char name[20];
    printf("Enter Name of Employee: \t");
    gets(name);
    printf("Enter total hours worked: \t");
    scanf("%f", &hours);
    if(hours<=8)
        totalWage = initWage;
    else if(hours>8 && hours<=12)
    {
        tempHour = hours-8;
        tempWage = tempHour*10;
        totalWage = tempWage + initWage;
    }
    else if(hours>12 && hours<=16)
    {
        tempHour = hours-12;
        tempWage = 4*10;
        totalWage = initWage + tempWage + (tempHour*20);
    }
    else if(hours>16 && hours<=20)
    {
        tempHour = hours-16;
        tempWage = (4*10) + (4*20);
        totalWage = initWage + tempWage + (tempHour*25);
    }
    else if(hours>20 && hours<=24)
    {
        tempHour = hours-20;
        tempWage = (4*10) + (4*20) + (4*25);
        totalWage = initWage + tempWage + (tempHour*40);
    }
    else
    {
        printf("A single day only has 24 hours.");
        getch();
        return 0;
    }
    printf("Total Wage: \t\t\t%0.2f", totalWage);
    getch();
    return 0;
}

As the program was written in the Code::Blocks IDE, here is the sample run after a successful build and run:

c program calculate wage of labour

Now provide the name of the laborer, say codescracker, and the total number of hours worked by him, say 21. Press the ENTER key to see the wage of labor as shown in the second snapshot of the sample run given here:

compute wage of labour on daily basis

Here is another sample run. In this case, the laborer has worked for all the day (24 hours). Let's see what the labor earnings will be for one full day based on the above pay scale:

print wage of labour c

Here are some of the main steps used in the above program:

C Quiz


« Previous Program Next Program »


Liked this post? Share it!