I re-edited my program but now whenever I try to compile it, it says that I have 2 unresolved externals. The only place where I declared external variables was before the calcPay() function, but I still got the same error message when I commented that line out. What's wrong with my program?
Here's what the error messages say:
Quote:
error LNK2020: unresolved token (0A000014) _streams
error LNK2001: unresolved external symbol
fatal error LNK1120: 2 unresolved externals
Code:#include <stdio.h>
#include <string.h>
// gets name and hourlyrate and hours worked from user
void userInput(char nameArray[][30], double hoursWorkedArray[], double hourlyRateArray[])
{
double hours[5], rate[5];
int i;
for (i=0; i<5; i++)
{
printf("Enter name.\n");
fflush(stdin);
scanf("%s", nameArray[i]);
printf("How many hours did they work this week?\n");
scanf("%lf", &hours[i]);
printf("What is their hourly rate?\n");
scanf("%lf", &rate[i]);
*hoursWorkedArray = hours[0];
*hourlyRateArray = rate[0];
}
}
// calculates base,gross,overtime, and net pay
double grossPay[5], basePay[5], overTime[5], netPay[5];
double calcPay (double hoursWorkedArray[], double hourlyRateArray[])
{
double base[5], over[5], gross[5], net[5];
int i;
for (i=0; i<5; i++)
{
if (hoursWorkedArray[i] > 40)
{
base[i] = hourlyRateArray[i] * hoursWorkedArray[i];
over[i] = (hoursWorkedArray[i] - 40) * 1.5 * hourlyRateArray[i];
gross[i] = (hourlyRateArray[i]*40) + over[i];
net[i] = (hourlyRateArray[i]*40) + over[i] - ((hourlyRateArray[i]*40) + over[i])*.2;
grossPay[i] = gross[i];
basePay[i] = base[i];
overTime[i] = over[i];
netPay[i] = net[i];
}
else
{
base[i] = hourlyRateArray[i] * hoursWorkedArray[i];
//taxesOwed[i] = (hourlyRateArray[i]*40) * .2;
gross[i] = (hourlyRateArray[i]*40) * .8;
over[i] = 0;
net[i] = (hourlyRateArray[i]*40) + over[i] - ((hourlyRateArray[i]*40) + over[i])*.2;
grossPay[i] = gross[i];
basePay[i] = base[i];
overTime[i] = over[i];
netPay[i] = net[i];
}
}
return *grossPay;
}
// calculates taxes owed
double calcTax (double *grossPay)
{
double taxPaid[5];
int i;
for (i=0; i<5; i++)
{
taxPaid[i] = *(grossPay + i) * .2;
return taxPaid[i];
}
}
//calculates the total amount paid to five emplorees
double totalPaid (double hoursWorkedArray[], double hourlyRateArray[])
{
double a,b,c,d,e;
a = calcPay(hoursWorkedArray, hourlyRateArray);
b = calcPay(hoursWorkedArray+1, hourlyRateArray+1);
c = calcPay(hoursWorkedArray+2, hourlyRateArray+2);
d = calcPay(hoursWorkedArray+3, hourlyRateArray+3);
e = calcPay(hoursWorkedArray+4, hourlyRateArray+4);
return a+b+c+d+e;
}
void printPay(char nameArray[][30], double hoursWorkedArray[], double hourlyRateArray[])
{
calcPay(hoursWorkedArray, hourlyRateArray);
double tax = calcTax(grossPay);
int i;
for (i=0; i<5; i++)
{
printf("Pay to %s: \n", nameArray[i]);
printf("Hours worked: %.2f\n", hoursWorkedArray+i);
printf("Hourly rate: $%.2f\n", hourlyRateArray+i);
printf(" Base pay: $%.2f\n Gross pay: $%.2f\n Gross pay: $%.2f\n Net pay: $%.2f\n Taxes paid: $%.2f\n", basePay[i], grossPay[i], netPay[i], tax);
}
}
int main(void)
{
double hourlyRate[5], hoursWorked[5];
char name[5][30];
userInput(name, hourlyRate, hoursWorked);
printPay(name, hourlyRate, hoursWorked);
return 0;
}