Question:
Computer Programming in C- I need help with extra credit assignment, please please please help!!!?
brendan
2015-04-14 18:47:15 UTC
Computer Programming in C

Computer Programming in C- I need help with extra credit assignment, please please please help!!!
Three answers:
MichaelInScarborough
2015-04-15 05:47:58 UTC
Hi Brendan: It seems that there is code which could be helpful to finalize your program. Why don't you post that code. as well as it would save time compared to redoing the whole assignment.

Is this code you would need?

#include

#include

#include



#define NUMBER_OF_EMPLOYEES 3

#define MORE_THAN_THREE 3.0

#define DAY_RATE (10)

#define DAY_MAX (20)

#define NIGHT_RATE (15)

#define NIGHT_MAX (30)



typedef struct {

double shift[2];

double earning;

}EMPLOYEE;



double get_double(const char prompt[], const char shift[], const int iSequence)

{

double ret;

char buffer[1024];



do {

fprintf(stdout, prompt, shift, iSequence);

memset(buffer, 0, sizeof(buffer));

if (fgets(buffer, sizeof(buffer), stdin)) {

if (sscanf(buffer, "%lf", &ret) == 1) {

break;

}

else {

fprintf(stdout, "Error: Floating point notation, only!\n");

}

}

else {

fprintf(stdout, "Error: Input Error!\n");

}

}while(1);

return ret;

}



double calculateDayCheck(double dblHours)

{

double amount = 0.0,

excess = 0.0,

sum = 0.0;

double earnings = 0.0;

if (dblHours > MORE_THAN_THREE) {

sum = 3.0;

excess = dblHours - sum;

}

else

sum = dblHours;

earnings = sum * DAY_MAX + excess * DAY_RATE;

return earnings;

}



double calculateNightCheck(double dblHours)

{

double amount = 0.0,

excess = 0.0,

sum = 0.0;

double earnings = 0.0;

if (dblHours > MORE_THAN_THREE) {

sum = 3.0;

excess = dblHours - sum;

}

else

sum = dblHours;

earnings = sum * NIGHT_MAX + excess * NIGHT_RATE;

return earnings;

}



int main()

{

const char prompt[] = "Enter the number of hours worked during the %s shift for employee %d> ";

const char *shift[] = {"day", "night"};

double (*fct[])(double dblHour) = {

&calculateDayCheck,

&calculateNightCheck

};

EMPLOYEE e[NUMBER_OF_EMPLOYEES];

for (int i = 0; i < NUMBER_OF_EMPLOYEES; i++) {

e[i].earning = 0.0;

for (int j = 0; j < 2; j++) {

e[i].shift[j] = get_double(prompt, shift[j], i + 1);

e[i].earning += fct[j](e[i].shift[j]);

}

}

for (int i = 0; i < NUMBER_OF_EMPLOYEES; i++) {

fprintf(stdout, "The pay check for employee %d is %8.2lf\n", i + 1, e[i].earning);

}

return 0;

}
brendan
2015-04-14 18:48:54 UTC
Here is a better photo of the assignment :)
?
2015-04-14 18:56:17 UTC
Please state what your specifically having trouble with... no one wants to do your assignment.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...