General discussion

Locked

Basic C Programming help??

By vineo76 ·
Can anyone in any possible way please help me with this basic C code. I will admit that this is homework, but it is late. I got caught up and stuck with trying to learn arrays, now I am stuck. I just need to get this assignment done, I will just read to catch up and do the future assignments myself. I am taking a six week summer course in C.
Write a method that prompts the user for hours worked, rate and name. Use parameter passing, and pass by reference.

here is the assignemt and the code as I have written it so far. Please make the following changes:


Write a method that calculates the gross, base and overtime pay, pass by reference.


Write a method that calculates tax, taking as input the gross pay, returning the tax owed.


Calculate the total amount paid (gross pay) for all 5 people. Use the return value from the method that calculates the gross pay.


Write a print method that generates the output, including the total amount paid, in addition to the data for each employee.


#include


main()


{

char name[25];

float rate = 0;

float hours = 0;

float basePay = 0;

float overTime = 0;

float grossPay = 0;

float netPay = 0;

int i;


for(i = 0; i < 5; i++) {


printf("\nWhat is your name? ");

scanf("%s", &name);

printf("\nHow much is your hourly pay? ");

scanf("%f", &rate);

printf("\nHow many hours did you work this week? ");

scanf("%f", &hours);


basePay = rate * hours;

grossPay = rate * 40 + (basePay - overTime);

overTime = (basePay - (1.5 * rate));

netPay = grossPay - (0.20 * grossPay);

if (hours > 40){

printf("\nPay for %s\n", name);

printf("\nHourly rate:\t $%.2f\n", rate);

printf("\nHours worked:\t $%.2f\n", hours);

printf("\nGross pay:\t $%.2f\n", grossPay);

printf("\nTaxes paid:\t $%.2f\n", 0.20 * grossPay);

printf("\nBase pay:\t $%.2f\n", basePay);

printf("\nOvertime pay:\t $%.2f\n", overTime);

printf("\nNet pay:\t $%.2f\n", netPay);


}

else {

printf("\nPay for %s\n", name);

printf("\nHourly rate:\t $%.2f\n", rate);

printf("\nHours worked:\t $%.2f\n", hours);

printf("\nGross pay:\t $%.2f\n", basePay);

printf("\nTaxes paid:\t $%.2f\n", 0.20 * basePay);

printf("\nBase pay:\t $%.2f\n", basePay);

printf("\nOvertime pay:\t $0.00\n");

printf("\nNet pay:\t $%.2f\n", basePay -(basePay * 0.20));


}


}

}

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Answered in Questions

by Tony Hopkinson In reply to Basic C Programming help? ...

at least twice....

Rest assured further attempts at posting the same request for us to do your homework will yield no better result.

Clues, tips, ways and means fine. 10/10 because we did it for you, not happening. Given you've been posting over three to four days, you could have this one done and be on question 2 by now.

Back to Peripheral Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums