ideone.com - http://ideone.com/LbwxMJ Please help. The above program failed exec
ID: 673065 • Letter: I
Question
ideone.com - http://ideone.com/LbwxMJ
Please help. The above program failed execution and can't find why.
// Description: This program prompts the user for the number of hours
// worked for each employee. It then calculates gross pay
// including overtime and displays the results in table. Functions
// and structures are used.
//
//*******************************************************************
#include
/* constants*/
#define STD_WORK_WEEK 40 /*number of regular pay hours*/
#define NUM_EMPL 5 /*number of employees*/
#define OT_RATE 1.5f /*overtime rate*/
/* Define a global structure to pass employee data between functions */
struct employee
{
long int id_number; /*employee clock number*/
float wage; /*HourlyWage for employee*/
float hours; /* hours worked in a given week */
float overtime; /* overtime hours */
float gross; /* gross pay */
};
/* Set up a local variable and initialize the clock and wages of my employees */
struct employee employeeData[NUM_EMPL] = {
{ 98401, 10.60 },
{ 526488, 9.75 },
{ 765349, 10.50 },
{ 34645, 12.25 },
{ 127615, 8.35 }
};
/* function prototypes */
void hours(float);
void wageRate(float*);
void overtime(float*,float*);
void Gross(float *,float*,float *,float*);
void printemployeeData(char id_number[][7], float wageRate[], float hrs[],
float ot[], float Gross[]);
int main()
{
/* Variable Declarations*/
float OT[NUM_EMPL] = {0}; /*calculate over time hours*/
float Hours[NUM_EMPL]={0}; /*read number of hours each employee worked*/
void Output_Results_Screen (struct employee emp [NUM_EMPL ], int size);
return 0;
/*input the hours each employee worked and store in an array hours*/
void readHours(float *hrs)
{
int i; /*loop index*/
printf("Enter Hours worked: ");
for(i=0;i {
printf("Enter Employee %d Hours:",i+1);
scanf("%f",&Hours[i]);
}
}
/*calculates the over time hours of each employee and stores in the array OT*/
void overtime(float *hrs,float *ot)
{
int i;
float temp;
for(i=0;i
{
temp = Hours[i]-STD_WORK_WEEK;
if(temp>=0)
OT[i]=temp;
}
}
esc to close
source code
close fullscreen
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
printf("Enter Hours worked: ");
for(i=0;i
{
printf("Enter Employee %d Hours:",i+1);
scanf("%f",&Hours[i]);
}
}
/*calculates the over time hours of each employee and stores in the array OT*/
void overtime(float *hrs,float *ot)
{
int i;
float temp;
for(i=0;i
{
temp = Hours[i]-STD_WORK_WEEK;
if(temp>=0)
OT[i]=temp;
}
input
Output
syntax highlight
Success time: 0 memory: 2108 signal:0
Success time: 0 memory: 2108 signal:0
/*calculates the gross pay of each employee and stores the pay in the array Gross*/
void calcGross(float *wageRate,float *hrs,float *ot,float *gross)
{
int i;
for(i=0;i {
gross[i]=((hrs[i]-ot[i])+(ot[i]*OT_RATE))*wageRate[i];
}
}
/*Prints the pay details of each employee*/
void printData(char clock[][7],float wageRate[],float hrs[],float ot[],float gross[])
{
int i;
float totalwageRate=0; /*to store total wages*/
float totalHours=0; /*to store total hours that all employees worked*/
float totalOT=0; /*to store the total over times that the employees worked*/
float totalGross=0; /*to store gross pay to be paid the employees*/
printf(" --------------------------------------------- ");
printf(" Clock# wageRate# Hours# OT# Gross# ");
printf("-------------------------------------------- ");
for(i=0;i {
printf("%6s %.1f %.1f %.1f %.2f ",clock[i],wageRate[i],hrs[i],ot[i],gross[i]);
totalwageRate=totalwageRate+wageRate[i];
totalHours=totalHours+hrs[i];
totalOT=totalOT+ot[i];
totalGross=totalGross+gross[i];
}
printf("------------------------------------------- ");
printf("%s %.1f %.1f %.1f %.2f ","Total",totalwageRate, totalHours, totalOT, totalGross);
printf("------------------------------------------- ");
printf("%s %.1f %.1f %.1f %.2f ","Average",totalwageRate/NUM_EMPL, totalHours/NUM_EMPL, totalOT/NUM_EMPL, totalGross/NUM_EMPL);
printf("------------------------------------------- ");
}
}
/*main*/
Explanation / Answer
/**C proram that prompts to enter hours worked and prints the
clock, hours, overtime, gross using functions and structures
*/
#include<stdio.h>
#include<conio.h>
/* constants*/
#define STD_WORK_WEEK 40 /*number of regular pay hours*/
#define NUM_EMPL 5 /*number of employees*/
#define OT_RATE 1.5f /*overtime rate*/
/* Define a global structure to pass employee data between functions */
struct employee
{
int id_number; /*employee clock number*/
float wage; /*HourlyWage for employee*/
float hours; /* hours worked in a given week */
float overtime; /* overtime hours */
float gross; /* gross pay */
};
/* function prototypes */
void readHours(float hrs[]);
void overtime(float [],float []);
void calcGross(float [],float [],float [],float []);
//pass strcture array to the printEmployee
void printemployeeData(int id_number[NUM_EMPL], float wageRate[], float hrs[], float ot[], float Gross[],struct employee emp [NUM_EMPL]);
//print the structure data using employee
void Output_Results_Screen (struct employee emp [NUM_EMPL], int size);
int main()
{
/* Variable Declarations*/
float OT[NUM_EMPL] = {0}; /*calculate over time hours*/
float Hours[NUM_EMPL]={0}; /*read number of hours each employee worked*/
float hrs[NUM_EMPL];
float ot[NUM_EMPL];
float gross[NUM_EMPL];
//initialize the wage rate and clock
float wageRate[NUM_EMPL]={10.60,9.75,10.50,12.25,8.35 };
int clock[NUM_EMPL]={98401,526488,765349,34645,127615};
//declare an array of employee
employee emp [NUM_EMPL];
//calling methods
readHours(Hours);
overtime(Hours,ot);
calcGross(wageRate,Hours,ot,gross);
printemployeeData(clock, wageRate,Hours, ot,gross,emp);
Output_Results_Screen (emp,NUM_EMPL);
getch();//pause the program output on console
return 0;
}
/*input the hours each employee worked and store in an array hours*/
void readHours(float hrs[])
{
int i; /*loop index*/
printf("Enter Hours worked: ");
for(i=0;i<NUM_EMPL;i++)
{
printf("Enter Employee %d Hours:",i+1);
scanf("%f",&hrs[i]);
}
}
/*calculates the over time hours of each employee and stores in the array OT*/
void overtime(float hrs[],float ot[])
{
int i;
for(i=0;i<NUM_EMPL;i++)
{
//calculate the Over time hours
if(hrs[i]>STD_WORK_WEEK)
{
ot[i]=hrs[i]-STD_WORK_WEEK;;
}
else
ot[i]=0;
}
}
/*calculates the gross pay of each employee and stores the pay in the array Gross*/
void calcGross(float wageRate[],float hrs[],float ot[],float gross[])
{
int i;
for(i=0;i<NUM_EMPL;i++)
{
//calculate the gross on hours and over time hours
if(hrs[i]<=STD_WORK_WEEK)
gross[i]=hrs[i]*wageRate[i];
else
gross[i]=40*wageRate[i]+(hrs[i]-40)*wageRate[i]*OT_RATE;
}
}
/*Prints the pay details of each employee*/
void printemployeeData(int clock[NUM_EMPL],float wageRate[],float hrs[],float ot[],float gross[],struct employee emp [NUM_EMPL])
{
int i;
float totalwageRate=0; /*to store total wages*/
float totalHours=0; /*to store total hours that all employees worked*/
float totalOT=0; /*to store the total over times that the employees worked*/
float totalGross=0; /*to store gross pay to be paid the employees*/
printf(" --------------------------------------------- ");
printf("Clock# wageRate# Hours# OT# Gross# ");
printf("-------------------------------------------- ");
for(i=0;i<NUM_EMPL;i++)
{
//fill the structure employee
emp[i].id_number=clock[i];
emp[i].wage=wageRate[i];
emp[i].hours=hrs[i];
emp[i].overtime=ot[i];
emp[i].gross=gross[i];
printf("%06d%10.2f%10.2f%10.1f%10.2f ",clock[i],wageRate[i],hrs[i],ot[i],gross[i]);
totalwageRate=totalwageRate+wageRate[i];
totalHours=totalHours+hrs[i];
totalOT=totalOT+ot[i];
totalGross=totalGross+gross[i];
}
printf("------------------------------------------- ");
printf("%-8s %10.2f %10.2f %10.2f %10.2f ",
"Total",totalwageRate, totalHours, totalOT, totalGross);
printf("------------------------------------------- ");
printf("%-8s %10.2f%10.2f%10.2f%10.2f ",
"Average",totalwageRate/NUM_EMPL, totalHours/NUM_EMPL, totalOT/NUM_EMPL, totalGross/NUM_EMPL);
printf("------------------------------------------- ");
}
//print the structure employee array on console
void Output_Results_Screen (struct employee emp [NUM_EMPL], int size)
{
printf("Printing using structure emp ");
printf(" --------------------------------------------- ");
printf("Clock# wageRate# Hours# OT# Gross# ");
printf("-------------------------------------------- ");
for(int i=0;i<NUM_EMPL;i++)
{
printf("%06d%10.2f%10.2f%10.1f%10.2f ",emp[i].id_number,emp[i].wage,emp[i].hours,emp[i].overtime,emp[i].gross);
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------
Sample output:
Enter Hours worked:
Enter Employee 1 Hours:60
Enter Employee 2 Hours:85
Enter Employee 3 Hours:40
Enter Employee 4 Hours:50
Enter Employee 5 Hours:25
---------------------------------------------
Clock# wageRate# Hours# OT# Gross#
--------------------------------------------
098401 10.60 60.00 20.0 742.00
526488 9.75 85.00 45.0 1048.13
765349 10.50 40.00 0.0 420.00
034645 12.25 50.00 10.0 673.75
127615 8.35 25.00 0.0 208.75
-------------------------------------------
Total 51.45 260.00 75.00 3092.63
-------------------------------------------
Average 10.29 52.00 15.00 618.52
-------------------------------------------
Printing using structure emp
---------------------------------------------
Clock# wageRate# Hours# OT# Gross#
--------------------------------------------
098401 10.60 60.00 20.0 742.00
526488 9.75 85.00 45.0 1048.13
765349 10.50 40.00 0.0 420.00
034645 12.25 50.00 10.0 673.75
127615 8.35 25.00 0.0 208.75
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.