Various problems with parameter passing...
Code:
#include<stdio.h>
#define MAX_EMP 5
// this function is passed the whole emp array
void displaymenu(char emp[MAX_EMP][15] );
int empselection();
// this function is passed just one employee
int gethoursworked(char emp[]);
int getpayrate();
int main()
{
int sel;
char emp[MAX_EMP][15] = {
"","Joe Smith", "Jane Smith", "Jane Doe", "Chuck Miller"};
int grosspay;
double netpay;
int hours;
int rate;
displaymenu(emp);
sel = empselection();
// do your error checking
hours = gethoursworked( emp[sel] );
rate = getpayrate();
grosspay = hours * rate;
netpay = (grosspay * .79);
if (hours ==1 )
printf("For %d hour, They will make $%6.2f.\n", hours, netpay);
else
printf("For %d hours, They will make $%6.2f.\n", hours, netpay);
return 0;
}
int gethoursworked(char emp[])
{
int hours;
printf("Enter hours worked for %s: ", emp);
scanf("%d", &hours);
return hours;
}
int empselection()
{
int sel;
printf("Enter a selection: ");
scanf("%d", &sel);
return sel;
}
int getpayrate()
{
int rate;
printf("What is their pay rate? ");
scanf("%d", &rate);
return rate;
}
void displaymenu(char emp[MAX_EMP][15])
{
int i;
puts("Enter 0 to quit");
puts("What Employee would you like to Calculate Pay for?");
for ( i = 1 ; i < MAX_EMP ; i++ ) {
printf( "%d: %s\n", i, emp[i] );
}
return;
}