Возникла проблема с вводом символьного значения if - else программа - PullRequest
0 голосов
/ 16 июня 2020

вот мой код. вопрос - напишите код, чтобы узнать, имеет ли студент право сдавать экзамен в зависимости от его / ее процента посещаемости. Если процент посещаемости студента превышает 75, он имеет право сдавать экзамен, в противном случае его / ее спросят, есть ли у него / нее заболевание. если да, он будет разрешен, иначе нет. Пожалуйста, помогите мне. Я не могу ввести данные во время инструкции if.

    int main()
    {
    char response;
    int clshld,per;
    int clsatnd;

    clshld = 330;   //total no of class held
    printf("no of class attended\n");
    scanf ("%d", &clsatnd);
    per=(clsatnd*100)/clshld;    //percentage formula
    printf ("\nattendence percentage is %d", per);

    if (per<75)
    {
        printf ("\ndo you have  a medical condition??");
        scanf ("%c", &response);
        if (response =='y')
        {
            printf ("\nyou can sit in the exam");
        }

        else 
        {
            printf ("\nattendence too low ! you can't sit in the exam.'");
        }
    }
    else
    {
        printf ("\nyou are eligible to sit in the exam.");
    }
    return 0;
    }

1 Ответ

0 голосов
/ 16 июня 2020

Попробуйте следующее:

#include<stdio.h>

int main()
{
    char response;
    int clshld,per;
    int clsatnd, trash;

    clshld = 330;   //total no of class held
    printf("no of class attended\n");
    scanf ("%d", &clsatnd);
    scanf("%c", &trash);
    per=(clsatnd*100)/clshld;    //percentage formula
    printf ("\nattendence percentage is %d", per);

    if (per<75)
    {
        printf ("\ndo you have  a medical condition?? ");
        scanf ("%c", &response);

        if (response =='y')
        {
            printf ("\nyou can sit in the exam");
        }

        else
        {
            printf ("\nattendence too low ! you can't sit in the exam.'");
        }
    }

    else
    {
        printf ("\nyou are eligible to sit in the exam.");
    }

    return 0;
}
...