2017-10-14 3 views
0

私はケース3で紛失しました。構造を閲覧し、入力が一致するかどうかを確認して従業員情報を更新しました。従業員のデータを表示および置換する方法は?

質問:「。数は、従業員の配列では見られないものの、 キープ、ユーザーにプロンプ​​トを表示 たdo-whileループを使用して従業員識別番号の入力をユーザーにプロンプ​​ト」

は、

「数が見つかったら、その識別番号と従業員 の現在の給与を表示し、入力に新しい 給与をユーザーに求める。入力値で、古い給与を交換してください。」あなたは次の変更を加える必要があり

#define _CRT_SECURE_NO_WARNINGS 

#include <stdio.h> 
#define SIZE 4 

struct employee_data{ 
    int Age; 
    int Int_Num; 
    double Salary; 
}; 

int main(void){ 

    int option = 0; 
    int NOE = 0; 
    printf("---=== EMPLOYEE DATA ===---\n");`enter code here` 

    struct employee_data emp[SIZE]; 
     // Employee_ID 
    int i; 
    do { 
     // Print the option list 
     printf("\n1. Display Employee Information\n"); 
     printf("2. Add Employee\n"); 

     printf("3. Update Employee Salary\n"); 
     printf("4. Remove Employee\n"); 
     printf("0. Exit\n\n"); 
     printf("Please select from the above options: "); 

     // Capture input to option variable 
     scanf("%d",&option); 
     printf("\n"); 

     switch (option) { 
      case 0: // Exit the program 
        printf("Exiting Employee Data Program. Good Bye!!!\n"); 
        break; 
      case 1: // Display Employee Data 
          // @IN-LAB 

        printf("EMP ID EMP AGE EMP SALARY\n"); 
        printf("====== ======= ==========\n"); 
        for (i=0; i<SIZE; i++){ 
         printf("%6d%9d%11.2lf\n", emp[i].Int_Num, emp[i].Age,emp[i] 
        // /printf("\n"); 
        } 
        // printf("%6d%9d%11.2lf", emp[1].Age, emp[1].Int_Num,emp[1] 
        // Use "%6d%9d%11.2lf" formatting in a 
        // printf statement to display 
        // employee id, age and salary of 
        // all employees using a loop construct 

        // The loop construct will be run for SIZE times 
        // and will only display Employee data 
        // where the EmployeeID is > 0 
        // printf("\n"); 
        break; 
      case 2: // Adding Employee 

        // @IN-LAB 

        // for (i = 0; i < SIZE; i++) 
        printf("Adding Employee\n"); 
        printf("===============\n"); 
        if(NOE < SIZE){ 
         // printf("ERROR!!! Maximum Number of Employees Reached\n" 
         printf("Enter Employee ID: "); 
         scanf("%d", &emp[NOE].Int_Num); 
         printf("Enter Employee Age: "); 
         scanf("%d", &emp[NOE].Age); 
         printf("Enter Employee Salary: "); 
         scanf("%11lf", &emp[NOE].Salary); 

         NOE++; 
        } 
        else{ 
         printf("ERROR!!! Maximum Number of Employees Reached\n"); 
        } 
        // Check for limits on the array and add employee 
        // data accordingly.} 
        break; 

        int number = 0; 
      case 3: printf("Update Employee Salary\n"); 
        printf("======================\n"); 
        do { 

         printf("Enter Employee ID: "); 
         scanf("%d", &number); 
         if(number == emp[NOE].Int_Num){ 
          printf("The current salary is %11lf", emp[NOE].Salary); 

          } 
          // else{ 
        }while (number != emp[NOE].Int_Num); 
        break; 
+0

'(数== EMP [NOE] .Int_Num){'場合: 'NOE'このために使用できません。 – BLUEPIXY

+0

また、' printf( "%6d%9d%11.2lf \ n"、emp [i] .Int_Num、emp [i] .Age、emp [i] ':コードがありません。 case 3: ' - >' case 3:; int number = 0; ' – BLUEPIXY

+0

'int number = 0; – BLUEPIXY

答えて

0

。最初に、現在のすべての従業員を指定された入力と比較します。一致するものがなければ、再度従業員の識別番号を求めるようにユーザに促す。

case 3: printf("Update Employee Salary\n"); 
       printf("======================\n"); 
       int flag = 0; 
       do{ 
        printf("Enter Employee ID: "); 
        scanf("%d", &number); 
        int i; 
        for(i =0; i<NOE ; i++) //checking for each current employee 
        { 
         if(number == emp[i].Int_Num) 
         { 
          printf("The current salary is %11lf", emp[i].Salary); 
          printf("\nInput new salary"); 
          scanf("%11lf", &emp[i].Salary); 
          flag = 1; 
          break; 
         } 

        } 
       } while (flag == 0); 
       break; 
関連する問題