Beginner that needs lots of help, Program that calculates employee data
A warning, I am a super beginner and I am having great difficulty and frustration trying to write this program I need to do for school. Any help will be greatly appreciated.
I need to write a program that asks for user input, employee name, hours worked, and hourly rate.
Write a method that prompts the user for hours worked, rate and name. Use parameter passing, and pass by reference.
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.
So far I have this:
Code:
#include <stdio.h>#include <stdlib.h>
int employeedata(char* ch, float* x, float *y)
{
printf("Enter your name:\n");
scanf_s("%s", *ch);
printf("Enter your hourly rate:\n");
scanf_s("%f", *x);
printf("Enter number of hours worked:\n");
scanf_s("%f",*y);
}
int calculatepay(float*a, float*b, float*c)
{
if (b > 40) {
printf("Base pay: %.2f\n", *a * 40);
printf("Overtime pay: %.2f\n", (*b - 40)*(*c * *a ));
printf("Your paycheck is: %.2f\n", ((*b - 40)*(*a * *c)) + (40 * *b));
printf("Taxes paid:%.2f\n", .2*((*b - 40)*(*a * *c) + (40 * *a)));
printf("Money taken home: %.2f\n", (*b - 40)*(*a * *c) + (40 * *a) - (.2*((*b - 40)*(*a * *c) + (40 * *a))));
}
else {
printf("Your paycheck is: %.2f\n", (*a * *b));
printf("Taxes paid: %.2f\n", .2*(*a * *b));
printf("Money taken home: %.2f\n", (*a * *b) - (.2*(*a * *b)));
}
printf("\n");
}
int main()
{
//variables
float rate[5], hours[5];
float overtimerate = 1.5;
char name[5][20];
int loop;
//loop 5 times
for (loop = 0; loop < 5; loop++)
{
//call function
employeedata(&name[loop], &rate[loop], &hours[loop]);
//use if to break out of loop after input if -1 is entered
if (strcmp(name, "-1") == 0)
break;
if (rate[loop] == -1)
break;
if (hours[loop] == -1)
break;
}
//output
//math calculations to calculate pay and taxes
//differentiate between overtime and non overtime pay
for (loop = 0; loop < 5; loop++){
printf("Name: %s\n", name[loop]);
printf("Hourly rate: %.2f\n", rate[loop]);
printf("Hours worked: %.2f\n", hours[loop]);
int calculatepay(&rate[loop], &hours[loop], &overtimerate);
}
system("pause");
return 0;
}
I have no idea how write a function that uses values from another function. Can someone explain to me how to do that? Also I have no idea how to fix my employeedata function. I get this error after inputting the first name:
Exception thrown at 0x0F87FB93 (ucrtbased.dll) in Project6.exe: 0xC0000005: Access violation writing location 0x004F0000.
If there is a handler for this exception, the program may be safely continued.