Hi guys... Good Day!
I'm having a problem with my code below.
The first case would enter the data of an employee... And the second case would search the ID number and will display the complete name of the employee. I've tried the method for loop and if, but it will terminate the case immediately without showing the output. What could be wrong with the method I used? Thank you in Advance...Code:#include <stdio.h> #include <string.h> main() { struct Payroll_System { char fname[40], sname[40], mi[2]; float id, bpay; } emp[5]; int z=0 , x, y; char sel; char choice; clrscr(); do { printf("PAYROLL SYSTEM\n\n"); printf("MENU:\n 1. Enter Employees Record\n 2. Process Payroll\n 3. Payroll Summary\n 4. Employee Payslip\n 5. Exit\n"); printf("Enter your choice: "); choice=getche(); switch(choice) { case '1': do { clrscr(); z++; printf("Write Record \n\n\n"); printf("Employee Number: "); scanf("%i", &emp[z].id); printf("Employee Name\n"); printf("First Name: "); scanf("%s", &emp[z].fname); printf("Middle Initial: "); scanf("%s", &emp[z].mi); printf("Last Name: "); scanf("%s", &emp[z].sname); printf("Basic Pay (Daily): "); scanf("%i", &emp[z].bpay); clrscr(); printf("Employee: %s, %s %s \nSuccessfully Added!\n\n\n", emp[z].sname, emp[z].fname, emp[z].mi); printf("Add New Record (y/n): "); scanf("%s" , &sel); clrscr(); } while(sel != 'n'); break; case '2': clrscr(); printf("Process Payroll \n\n\n"); printf("Enter Employee Number: "); scanf("%i", &y); for(x=1;x<=z;x++) { if(y == emp[x].id) { printf("Employee Name: %s, %s %s", emp[x].sname, emp[x].fname, emp[x].mi); } } break; } } while(choice!= '5'); }



LinkBack URL
About LinkBacks




