parameter passing and pointers
I wrote another program for homework that calculates 5 employees' weekly pay using parameter passing and pointers, but when I tried to compile the program I got the following errors:
Quote:
'userInput' : cannot convert parameter 1 from 'char (*)[5][30]' to 'char []'
'printPay' : cannot convert parameter 1 from 'char (*)[5][30]' to 'char []'
I'm guessing the problem is with one of my pointers? I can't seem to figure out what exactly is wrong with my code though. Can anyone help?
Code:
#include <stdio.h>
#include <string.h>
// gets name and hourlyrate and hours worked from user
void userInput(char nameArray[], double hourlyRateArray[], double hoursWorkedArray[])
{
int i;
for (i=0; i<5; i++)
{
printf("Enter name.\n");
scanf("%s", &nameArray[i]);
printf("What is their hourly rate?\n");
scanf("%f", &hourlyRateArray[i]);
printf("How many hours did they work this week?\n");
scanf("%f", &hoursWorkedArray[i]);
}
}
// calculates base,gross,overtime, and net pay
double calcPay (double hoursWorkedArray[], double hourlyRateArray[])
{
double basePay[5], overTime[5], grossPay[5], netPay[5];
int i;
for (i=0; i<5; i++)
{
if (hoursWorkedArray[i] > 40)
{
basePay[i] = hourlyRateArray[i] * hoursWorkedArray[i];
overTime[i] = (hoursWorkedArray[i] - 40) * 1.5 * hourlyRateArray[i];
grossPay[i] = (hourlyRateArray[i]*40) + overTime[i];
netPay[i] = (hourlyRateArray[i]*40) + overTime[i] - ((hourlyRateArray[i]*40) + overTime[i])*.2;
}
else
{
basePay[i] = hourlyRateArray[i] * hoursWorkedArray[i];
//taxesOwed[i] = (hourlyRateArray[i]*40) * .2;
grossPay[i] = (hourlyRateArray[i]*40) * .8;
overTime[i] = 0;
netPay[i] = (hourlyRateArray[i]*40) + overTime[i] - ((hourlyRateArray[i]*40) + overTime[i])*.2;
return basePay[i], grossPay[i], overTime[i], netPay[i];
}
}
}
// calculates taxes owed
double calcTax (double grossPay[])
{
int i;
for (i=0; i<5; i++)
{
double taxPaid[5];
taxPaid[i] = grossPay[i]*.2;
return taxPaid[i];
}
}
//calculates the total amount paid to five emplorees
double totalPaid (double grossPay[])
{
double totalPaid;
totalPaid = grossPay[0] + grossPay[1] + grossPay[2] + grossPay[3] + grossPay[4];
return totalPaid;
}
void printPay(char nameArray[], double hoursWorkedArray[], double hourlyRateArray[])
{
int i;
for (i=0; i<5; i++)
{
printf("Pay to %s: \n", nameArray[i]);
printf("Hours worked: %lf\n", hoursWorkedArray[i]);
printf("Hourly rate: $%.2lf\n", hourlyRateArray[i]);
printf(" Base pay: $%.2lf\n Gross pay: $%.2lf\n Gross pay: $%.2lf\n
Net pay: $%.2lf\n Taxes paid: $%.2lf\n", calcPay(hoursWorkedArray, hourlyRateArray));
}
}
int main(void)
{
double hourlyRate[5], hoursWorked[5];
char name[5][30];
userInput(name, hoursWorked, hourlyRate);
printPay(name, hoursWorked, hourlyRate);
return 0;
}