This is a homework for my C programming class. The program calculates employee gross pay, tax pay, and net take home pay.
The program runs but it automatically ends saying "segmentation fault(core dumped) The error message says:
line 127: warning: passing argument 1 of 'Prompt' from incompatible pointer type
line 13: note: expected 'char*' but argument is of type 'char*(*)[5]'
line 143: warning: passing argument 1 of 'PrintOutput' from incompatible pointer type
line 90: note: expected 'char*' but argument is of type 'char(*)[20][5]'
I don't quite understand the int type because I declared the first_name variable as an array in the main() function.
I don't understand the rest of the errors either.
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Prompt(char* a, float* b, float* c)
{
int i;
for (i = 0; i < 5; i++) {
printf("Enter name: ");
scanf("%s", &a[i]);
if (strcmp(&a[i],"-1") == 0) {
break;
}
printf("Enter hourly rate: ");
scanf("%f", &b[i]);
if (b[i] == -1) {
break;
}
printf("Enter hours worked: ");
scanf("%f", &c[i]);
if (c[i] == -1) {
break;
}
}
return;
}
void GrossPay(float* grosspay, float* basepay, float* overtimepay,
float* rate, float* hours)
{
int i;
if (hours[i] > 40) {
overtimepay[i] = (hours[i] - 40) * (rate[i]) * 1.5;
basepay[i] = rate[i] * hours[i];
grosspay[i] = rate[i] * hours[i] + (hours[i] - 40) * (rate[i]) * 1.5;
} else {
overtimepay[i] = 0;
basepay[i] = rate[i] * (hours[i]);
grosspay[i] = basepay[i];
}
return;
}
float Taxes(float gross_pay[])
{
int i;
float taxes_owed[5];
for (i = 0; i < 5; i++) {
taxes_owed[i] = 0.2 * gross_pay[i];
}
return taxes_owed[5];
}
float CalculateTotal(float gross_pay[])
{
int i;
float total_pay = 0;
for (i = 0; i < 5; i++) {
total_pay += gross_pay[i];
}
return total_pay;
}
void PrintOutput(char first_name[5], float* rate, float* hours,
float* gross_pay, float* base_pay, float* overtime_pay,
float* taxes_owed, float* net_pay, float* total_pay)
{
int i;
for (i = 0; i < 5; i++) {
printf("\nPay to: %s\n", &first_name[i]);
printf("Hours worked: %5.1f\n", hours[i]);
printf("Hourly rate: $%5.2f\n", rate[i]);
printf("Gross pay: $%5.2f \n", gross_pay[i]);
printf("Base pay: $%5.2f \n", base_pay[i]);
printf("Overtime pay: $%5.2f\n", overtime_pay[i]);
printf("Taxes paid: $%5.2f\n", taxes_owed[i]);
printf("Net pay: $%5.2f\n\n", net_pay[i]);
}
printf("Total paid to all employees= $%5.2f\n", *total_pay);
return;
}
int main()
{
char first_name[20][5];
float rate[5];
float hours[5];
float gross_pay[5];
float base_pay[5];
float overtime_pay[5];
float taxes_owed[5];
float net_pay[5];
float total_pay;
int i;
Prompt(first_name, rate, hours);
GrossPay(gross_pay, base_pay, overtime_pay, rate, hours);
taxes_owed[5] = Taxes(gross_pay);
total_pay = CalculateTotal(gross_pay);
for (i = 0; i < 5; i++) {
net_pay[i] = gross_pay[i] - taxes_owed[i];
}
PrintOutput(&first_name, rate, hours, gross_pay, base_pay, \
overtime_pay, taxes_owed, net_pay, &total_pay);
return 0;
}
Sorry I am very new at coding, never took a class on coding before and I am super confused right now, especially on parameter passing.