#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    How to fix error bangluongnv(b) and timkiemnv()


    I am trying fix bug but impossible
    Code:
     
    
    #include  <stdio.h>
    #include  <conio.h>
    #include  <string.h>
    #include  <ctype.h>
    #define max 100   
    
    float luongCB = 750000;
    
    typedef struct 
    {
        char manv[15];
        char ten[30];
        char hodem[30]; 
        char ngaysinh[30];   
        float bacluong;
        float phucap;  
        
    }nhanvien;
    
    int tongnv;
    
    void menu();/*menu chinh*/
    
    void luongcoban();
    void menuqlnv(); /*mennu quan ly nhan vien*/
    int  qlnv();     /*ham quan ly nhan vien*/
    void lietkenv(); /*ham liet ke danh sach nhan vien*/
    void themnv();   /*ham them moi nhan vien*/
    void suannv();    /*ham sua nhan vien*/
    void xoannv();   /*ham xoa nhan vien*/
    void bangluongnv();
    
    void timkiemnv();/*ham tim kiem nhan vien*/
    void timtennv();
    void timbacluong();
    
    void menu()
    {
         
      printf("\n\n\t************MENU***************");  
      printf("\n\t-------------------------------");
      printf("\n\t1. Quan ly luong co ban.");
      printf("\n\t2. Quan ly nhan vien.");
      printf("\n\t3. Bang luong. ");
      printf("\n\t4. Tim kiem. ");
      printf("\n\t0. Thoat");
      printf("\n\t-------------------------------");
      
    }
    /* Cung cap chuc nang quan ly luong co ban cua nhan vien */
    void luongcoban()
        {
          printf("\n\tMoi nhap luong co ban: ");
          scanf("%f",&luongCB);
          
          printf("\n\tLuong co ban: %.3f", luongCB);
        }
    
    
    void menuqlnv()
    {
         printf("\n");     
         printf("\n\t   *      *      *     *      *  ");
         printf("\n\t***** MENU QUAN LY NHAN VIEN ****");
         printf("\n\t--------------------------------");
         printf("\n\t1. Liet ke danh sach nhan vien.");
         printf("\n\t2. Them moi nhan vien.");
         printf("\n\t3. Sua thong tin nhan vien .");
         printf("\n\t4. xoa thong tin nhan vien.");
         printf("\n\t0. Thoat.");
         printf("\n\t--------------------------------");
    }
    
    void themmoinv(nhanvien b[])
    {
         int i,n;
         
         printf("\n\n\tMoi ban nhap so luong nhan vien can them: ");
         scanf("%d",&n);
         
         for(i=0;i<n;i++)
         {
                        
            printf("\n\n\n\tNhap thong tin nhan vien %d",i+1);
            printf("\n\t--------------------------------");
            printf("\n\n\tNhap ma nhan vien : ");
            fflush(stdin);
            gets(b[i].manv);
            
            printf("\n\tNhap ho dem nhan vien : ");
            fflush(stdin);
            gets(b[i].hodem);
            
            
            printf("\n\tNhap ten nhan vien : ");
            fflush(stdin);
            gets(b[i].ten);
            
            
            printf("\n\tNhap ngay sinh nhan vien : ");
            fflush(stdin);
            gets(b[i].ngaysinh);              
            
            
            printf("\n\tNhap bac luong : ");        
            scanf("%f",&b[i].bacluong);
            
            printf("\n\tNhap phu cap : ");
            fflush(stdin);        
            scanf("%f",&b[i].phucap);
            printf("\n\t--------------------------------");
            
         }
       tongnv=tongnv+n;
      
    }
    
    
    void lietkenv(nhanvien b[])
    {
         int i,j;
         printf("\n\t\t  ****** THONG TIN NHAN VIEN ******\n ");
         printf("\n\t======================================\n");
         printf("\n\t|MNV   |    Ho va ten      |  Ngay sinh    | Bac luong |  Phu cap  |\n");
         printf("\t====================================\n");
         
         for(i=0;i<tongnv;i++)
          {
           char tg[60];
             
             strcpy(tg,b[i].hodem);
             strcat(tg," ");
             strcat(tg,b[i].ten);
           printf("\t%-7s|%-20s|%-14s|%-12.3f|%-10.3f|\n",b[i].manv,tg,b[i].ngaysinh,b[i].bacluong,
                                                                                        b[i].phucap);
           
          } 
          printf("\t========================================\n"); 
        
    }
    
    
    
    void suanv(nhanvien b[])
    {    
         int i = 0;
    	printf("\n---------------------");
    	printf("Thong tin cu");
    	lietkenv(b);
    	fflush(stdin);
    	printf("\n---------------------");
    	printf("\nNhap vao thong tin cua nhan vien");
        
        printf("\n- Ma nhan vien: "); gets(b[i].manv);
    	printf("-    Ho va dem: "); gets(b[i].hodem);
    	printf("-          Ten: "); gets(b[i].ten);
    	printf("-    Ngay sinh: "); gets(b[i].ngaysinh);
    	
    	printf("-   Bac  luong: "); scanf("%f", &b[i].bacluong);
    	printf("-      Phu cap: "); scanf("%f", &b[i].phucap);
    	printf("\n\n Du lieu da duoc cap nhat");
    	printf("\n--------------------------------");
    }
    
    void xoanv(nhanvien b[])
    {
      char manv1[15], traloi;
      int i = 0, j;
      
      printf("\n\tCho biet ma nhan vien can xoa : ");
      fflush(stdin);
      gets(manv1);
      
    
        while (i<tongnv)
    
          if (strcmp(b[i].manv, manv1) == 0)
          {
      
             printf("\n\tCo muon xoa khong (C/K)?: ");
             
             do {
               traloi = toupper(getch());
             } while (traloi != 'C' && traloi != 'K');
             
             /*putc(traloi, stdout);*/
             printf("%c",traloi);
             if (traloi == 'C')
             {
               tongnv--;
               memcpy(&b[i],&b[i+1],sizeof(nhanvien));
               break;
               }
          }
          else
            i++;
    }   
    /* Cung cap chuc nang quan ly thong tin nhan vien */
    int qlnv()
    {
         nhanvien b[max];
         int chon,done=0;
         
         while(!done)
         {              
             menuqlnv();
             printf("\n\tChon : ");
             scanf("%d",&chon);
             switch(chon)
             {
                case 1:
                     lietkenv(b);
                     break; 
                case 2:     
                     themmoinv(b);
                     break;
                case 3:
                     suanv(b);
                     break;
                case 4:
                     xoanv(b);
                     break;      
                case 0:
                     done=1;
                     break;    
            }
          }   
       }
    
    /* Cung cap chuc nang tim kiem thong tin nhan vien */
    void timkiemnv()
     {
         int i;
         int chon;
         
        while(1)
          {
          printf("\n\t********* MENU TIM KIEM NHAN VIEN *************\n");
          printf("\n\t1. Tim nhan vien theo ten.\n");
          printf("\n\t2. Tim nhan vien theo bac luong.\n");
          printf("\n\t3. Thoat\n");
          printf("\n\tChon: ");
          scanf("%d",&chon);
          
              switch(chon)
              {
              case 1:
                   timtennv();
                   break;
              case 2:
                   timbacluong();
                   break;
              case 3:
                   exit(1);
                   break;
              default:
                     printf("Ban chon khong dung"); 
                     break;
              }
         }
     }
    
    void timtennv(nhanvien b[])
    {
     
        char tenct[30];
        int i;
        int check=0;
        fflush(stdin);
        printf("\n\tNhap vao ten nhan vien can tim : ");
        gets(tenct);
    
        for(i=0;i<tongnv;i++)
          {
            if(strcmp(b[i].ten,tenct)==0) 
            {
                 check=1;
                 printf("\n\t\t  ****** THONG TIN NHAN VIEN ******\n ");
                 printf("\n\t==================================================");
                 printf("\n\t|  MNV    |      TenNV     |\n");
                 printf("\t==================================================\n");
                 
                 
                   
                 printf("\t|%-10s|%-17s|\n",b[i].manv,b[i].ten);
                   
                  
                 printf("\t==================================================\n"); 
                 break;
             
             }
          }
        if(check==0) printf("\n\n\tkhong co hoac ban nhap sai\n");
        
    }
    
    void timbacluong(nhanvien b[])
    {
     
        int bacluongct;
        int i;
        int check=0;
        fflush(stdin);
        printf("\n\tNhap vao  bac luong cua nhan vien can tim : ");
         scanf("%d",&bacluongct);
    
        for(i=0;i<tongnv;i++)
          {
            if(b[i].bacluong==bacluongct) 
            {
                 check=1;
                 printf("\n\t\t  ****** THONG TIN NHAN VIEN ******\n ");
                 printf("\n\t==================================================");
                 printf("\n\t|MNV      |      Ho va ten     |   Bac luong   |\n");
                 printf("\t==================================================\n");
                   
                     char tg[60];
                 
                 strcpy(tg,b[i].hodem);
                 strcat(tg," ");
                 strcat(tg,b[i].ten);
                 
                 printf("\t%-10s|%-20s|%-16.3f|\n",b[i].manv,tg,b[i].bacluong);
                  
                 printf("\t==================================================\n"); 
                 break;
             }
          }
        if(check==0) printf("\n\n\tkhong co hoac ban nhap sai\n");
        
    }
     /* Cung cap chuc nang hien thi bang luong cua nhan vien */
    void bangluongnv(nhanvien b[])
    {
         int i,j;
         char hodem[30];
         char ten[30];
         float thunhap;
         
         printf("\n\t*******************************************\n");
         printf("\n\t                  BANG LUONG                 \n");
         printf("\n\t*******************************************\n");
         printf("\n\t|STT  |  MaNV    |    Ho va ten    |     Thu nhap |\n");
         
         for(i=0; i<tongnv; i++)
    	 {
             char tg[60];
             
             strcpy(tg,b[i].hodem);
             strcat(tg," ");
             strcat(tg,b[i].ten); 
             
             for(i=0; i<i-1; i++)
             {
             for(j=0; j<tongnv-1-i; j++)
             {
                 if(tg[j]>tg[j+1])
                 {
                      int tam = tg[j];
                      tg[j] = tg[j+1];
                      tg[j+1] = tam;
                 }
             }  
           }
             
             float thunhap = (luongCB * b[i].bacluong) + b[i].phucap;
             
         printf("\n\t|%-6d|%-10s|%-18s|-%15.3f|",i+1,b[i].manv,tg,thunhap);
             
         }
         
         printf("\n\t------------------------------------------------------\n");
    }
    
    
    
    int main()
    {
         nhanvien b[max];
         int chon;
         system("cls");
              
         while(1)
         {              
             menu();
             printf("\n\tChon : ");
             scanf("%d",&chon);
             switch(chon)
             {
                case 1:
                     luongcoban();
                     break; 
                case 2:     
                     qlnv();
                     break;
                case 3:
                     bangluongnv(b);
                     break; 
                case 4:
                     timkiemnv();
                     break;    
                case 0:
                     exit(0);
                     break;  
             }
          } 
       fflush(stdin);  
       getch();
    }
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,861
    Rep Power
    1960
    You have to explain what problems you got. Do you get any error message?
    what is your expectation?

IMN logo majestic logo threadwatch logo seochat tools logo