Compile with warnings turned all the way up:
Code:
$ make foo
gcc -Wall -ggdb3 -std=c99 -o foo foo.c -lm -lpthread
foo.c: In function ‘main’:
foo.c:30:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[20]’ [-Wformat]
foo.c:32:5: warning: format ‘%f’ expects argument of type ‘float *’, but argument 2 has type ‘double *’ [-Wformat]
foo.c:34:5: warning: format ‘%f’ expects argument of type ‘float *’, but argument 2 has type ‘double *’ [-Wformat]
Your scanf calls are wrong. Drop the & from line 30, the name of an array is already a pointer to the first element, so you don't need it. The other two, read the docs for scanf, you need a l (ell) in there to scan a double: %lf.
If you are trying to find a problem in a calculated value, it's a good idea to print or watch in the debugger, and make sure you are using the right values for your calculation. If you added the following printf, you might see something:
Code:
$ tail foo.c
for (i = 0; i < MAXARRAY; i++){
printf("\ncalculating with pay_rate = %f, hrs_worked = %f\n", payment[i].pay_rate, payment[i].hrs_worked);
payment[i].emp_pay = payment[i].pay_rate * payment[i].hrs_worked;
payment[i].gross_pay += payment[i].emp_pay;
printf("\nThe Pay for employee #%d is %f", payment[i].idnum, payment[i].emp_pay);
}
return 0;
}
$ make foo
<warnings snipped>
$ ./foo
This program will calculate the amount of pay for employees entered.Program will calculate pay for up to 6 employees.
Enter employee ID Number: 1
Enter employee Last Name: aaa
Enter employee Pay Rate: $12.34
Enter employee Hours Worked: 7
Enter employee ID Number: 2
Enter employee Last Name: bbb
Enter employee Pay Rate: $13.99
Enter employee Hours Worked: 5
calculating with pay_rate = 0.000000, hrs_worked = 0.000000
The Pay for employee #1 is 0.000000
calculating with pay_rate = 0.000000, hrs_worked = 0.000000
The Pay for employee #2 is 0.000000
Uh oh, all your values are zero, another sign you read them incorrectly.
A few more notes, use a %d in the printf on line 23, along with MAXARRAY so your output will always be correct, even if you change MAXARRAY to 2:
Code:
printf("Program will calculate pay for up to %d employees.\n", MAXARRAY);
Also, a couple aesthetic things: print an empty line between entering each employee, it makes it easier to know when you're on a new employee, and an empty line after the last line of output, so your command prompt looks correct after your program is done.