switch functions in c -
trying create menu driven employee data program. don't know how create functioning menu , having trouble getting menu options work such editing entered employee info. appreciate can on this. errors arising
edit employees function: redefinition; different basic types.
in
main
—when calling menu function usingmenu(&payroll)
, error message is, cannot convertinput*
input
.also in main—the function
employeeinfo(&payroll)
giving error message, cannot convertinput*
input
.
i'm sure there many other mistakes making if see please guide me in right direction.
#include <stdio.h> #include <stdlib.h> #include <string.h> //this macro intended use emplyname array. #define size 20 //this struct has varibles using in functions typedef struct { char emplyname[5][size]; float emplyhours[5]; float emplyrate[5]; float emplygross[5]; float emplybase[5]; float emplyovrt[5]; float emplytax[5]; float emplynet[5]; float emplytotal[5]; }input; void menu(void); void employeeinfo(input* emply); void editemployees(input* emply); void print(input* emply); int main(void) { input payroll={"",0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f}; int choice; menu(&payroll); scanf_s("%d", &choice); switch (choice){ case '1': employeeinfo(&payroll); break; case '2': editemployees(&payroll); break; case '3': break; case '4': print(&payroll); break; default: printf("invalid entry\n"); } system("pause"); } void employeeinfo(input *emply) { int i; (i = 0; < 5; i++){ printf("enter employee name -1 end.\n"); scanf_s("%s", &emply->emplyname[i]); if (strcmp(emply->emplyname[i], "-1") == 0){ break; } printf("enter employee hours.\n"); scanf_s("%f", &emply->emplyhours[i]); printf("enter hourly rate.\n"); scanf_s("%f", &emply->emplyrate[i]); } } void calculations(input *emply)/*write method calculates gross, base , overtime pay, pass reference.*/ { int i; = 0; (i = 0; < 5; i++){ if (emply->emplyhours[i] > 40) { emply->emplyovrt[i] = (emply->emplyhours[i] - 40) * (emply->emplyrate[i] * 1.5); } emply->emplygross[i] = (((emply->emplyhours[i])*(emply->emplyrate[i])) + emply->emplyovrt[i]); emply->emplybase[i] = (emply->emplygross[i]) - (emply->emplyovrt[i]); emply->emplytax[i] = ((emply->emplygross[i])*.2); emply->emplynet[i] = (emply->emplygross[i]) - (emply->emplytax[i]); emply->emplytotal[0] += emply->emplygross[i]; } } void print(input *emply) { int i; (i = 0; < 5; i++) { if (strcmp(emply->emplyname[i], "-1") == 0){ break; } printf("employee name:%s\n", emply->emplyname[i]); printf("hours worked:%.2f\n ", emply->emplyhours[i]); printf("hourly rate:%.2f\n", emply->emplyrate[i]); printf("gross pay:%.2f\n", emply->emplygross[i]); printf("base pay:%.2f\n", emply->emplybase[i]); printf("overtime pay:%.2f\n", emply->emplyovrt[i]); printf("taxes paid:%.2f\n", emply->emplytax[i]); printf("net pay:%.2f\n", emply->emplynet[i]); } printf("total paid employees : %.2f\n", emply->emplytotal[0]); } void editemployees(input *emply){ int j; int index = 1; int i; printf("choose employee."); (j = 1; j < 5; j++); { printf("%d.%s", index, emply->emplyname[j]); } scanf_s("%d", &i); employeeinfo(emply); } void menu(void){ printf("main menu\n"); printf("1. add employee\n"); printf("2. edit employee\n"); printf("3. print employee\n"); printf("4. print employees\n"); printf("0. exit\n"); }
to start with
1. edit employees function: redefinition; different basic types.
you need forward declare function prototype.
2.
menu(&payroll)
cannot convert 'input*' 'input'.
your function declaration , definition not match.
- in declaration, have
void menu(input payroll);
- in definition, have
void menu(void){ //
- you call
menu(&payroll);
all above 3 different. stick one.
3. employeeinfo(&payroll) cannot convert 'input*' 'input'.
again, mismatch between function declaration , definition. change function declaration
void employeeinfo(input payroll);
to
void employeeinfo(input* payroll);
Comments
Post a Comment