내 프로그램이 스위치 케이스 뒤에 오는 코드를 인쇄하지 않는 이유는 무엇입니까? 스위치 케이스가 실행 된 후 종료됩니다.

Osnapitsdina

스위치 케이스를 숨기면 코드가 제대로 작동합니다. switch case에 대해 잘못된 int를 입력하면 switch case 다음에 printf 문이 실행됩니다. 스위치 케이스에 유효한 int를 입력하면 스위치 케이스에 들어가서 거기서 끝나고 나중에 printf 문을 건너 뜁니다. 괜찮아 보이지만 분명히 그렇지 않습니까?

#include<stdio.h>
#include<string.h>
#define OT 14.00

void main ()
{
    char name[40];
    char position[20];
    char position_name[20];
    int id, o_time, code;
    float allowance, bonus, nett_salary, salary;
    
    printf ("-----------------------------------");
    printf ("\n         PAYROLL SYSTEM");
    printf ("\n-----------------------------------");
    printf ("\n      1. Lecturer");
    printf ("\n      2. Clerk");
    printf ("\n      3. Technician");
    printf ("\n-----------------------------------");

    printf ("\nEnter staff name     : ");
    scanf("%[^\n]s",&name);
    printf ("Enter staff ID       : ");
    scanf ("%d", &id);
    printf ("Enter position       : ");
    scanf ("%d", &code);
    printf ("Enter salary         : RM ");
    scanf ("%f", &salary);
    
    
    
    
    switch (code)
    {
        case 1:
        strcpy (position, "Lecturer");
        printf ("Enter allowance      : RM ");
        scanf ("%f", allowance);
        nett_salary = salary+allowance;
        break;
        
        case 2:
        strcpy (position, "Clerk");
        printf ("Enter bonus          : RM ");
        scanf ("%f", bonus);
        nett_salary = salary+bonus;
        break;
        
        case 3:
        strcpy (position, "Technician");
        printf ("Enter overtime hours : ");
        scanf ("%d", o_time);
        nett_salary = salary+(o_time*OT);
        break;
        
        default:
        strcpy(position,"Invalid");
        nett_salary = 0;
    }
    
    printf ("\nStaff Name      : %s", name);
    printf ("\nStaff No.       : %d", id);
    printf ("\nPosition        : %s", position);    
    printf ("\nSalary          : RM%.2f", salary);
    printf ("\n------------------------------------");
    printf ("\nNett Salary     : RM %.2f", nett_salary);
    printf ("\n------------------------------------");
    
    
}
크리슈나 칸트 예누 뮬라
scanf ("%f", allowance); // In case 1
scanf ("%f", bonus);     // In case 2
scanf ("%d", o_time);    // In case 3

&scanf문구 에서 누락되었습니다 .

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관