Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I created a c program that will calculate the employee salary including Overtime

ID: 3549948 • Letter: I

Question

I created a c program that will calculate the employee salary including Overtime for any hours worked over 40 hours.

The program is running successfully however, the Gross Pay is not calculating correctly when there is overtime worked.

When entering the following information, the Gross Pay should be $598.90.

Number of employees=1

Clock #=98401

Wage=10.60

Hours=51

Please help with finding what I did wrong in the following code:

#include <stdio.h>
#include <stdlib.h>
#define STD_HOURS 40.0
int main()
{

int datacount = 0; /* Number of test data sets */
int clockNo = 0;
float wage = 0.0;
float hours = 0.0;
float gross = 0.0; /* Variables to hold gross salaries */
float ot = 0.0;
float otpay =0.0;
int i = 0; /* loop counter */


printf ("This is a program to calculate gross pay. ");
printf ("You will be prompted for employee data. ");
printf("How many employees data you wish to enter? "); /* Prompt text */
scanf("%d",&datacount); /* Get test data count from the user */

do
{

printf("Enter Employee's Clock #: ");
scanf("%d", &clockNo);
printf("Enter hourly wage: ");
scanf("%f", &wage);
printf("Enter no. of hours worked: ");
scanf("%f", &hours);

gross = wage * hours;

if(hours>STD_HOURS)
{
ot=hours-STD_HOURS;
otpay=ot * (wage + (wage/2));
}
i++;



printf("------------------------------------------------ ");
printf("%6s","Clock#");
printf("%10s","Wage");
printf("%10s","Hours");
printf("%10s","OT:");
printf("%10s ","Gross");
printf("------------------------------------------------ ");



printf("%06d",clockNo);
printf("%10.2f",wage);
printf("%10.1f",hours);
printf("%10.2f",ot);
printf("%10.2f ",gross);

}

while(i < datacount);

}


Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#define STD_HOURS 40.0
int main()
{

int datacount = 0; /* Number of test data sets */
int clockNo = 0;
float wage = 0.0;
float hours = 0.0;
float gross = 0.0; /* Variables to hold gross salaries */
float ot = 0.0;
float otpay =0.0;
int i = 0; /* loop counter */


printf ("This is a program to calculate gross pay. ");
printf ("You will be prompted for employee data. ");
printf("How many employees data you wish to enter? "); /* Prompt text */
scanf("%d",&datacount); /* Get test data count from the user */

do
{

printf("Enter Employee's Clock #: ");
scanf("%d", &clockNo);
printf("Enter hourly wage: ");
scanf("%f", &wage);
printf("Enter no. of hours worked: ");
scanf("%f", &hours);


if(hours>STD_HOURS)
{
   
ot=hours-STD_HOURS;
otpay=ot*1.5*wage;
gross=STD_HOURS*wage+otpay;
}
else
gross = wage * hours;

i++;



printf("------------------------------------------------ ");
printf("%6s","Clock#");
printf("%10s","Wage");
printf("%10s","Hours");
printf("%10s","OT:");
printf("%10s ","Gross");
printf("------------------------------------------------ ");



printf("%06d",clockNo);
printf("%10.2f",wage);
printf("%10.1f",hours);
printf("%10.2f",ot);
printf("%10.2f ",gross);

ot=0.0;
otpay=0.0;
gross=0.0;
clockNo=0;
hours=0;
wage=0;
}

while(i < datacount);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote