0

here is my code. the question is- write a code to check weather a student is eligible to sit in the exam based on his/her attendance percentage. If the student has attendance percentage more than 75, he is eligible to sit in the exam otherwise, he/she will be asked weather he/she has a medical condition. if yes, he will be allowed otherwise not. Please help me out. I am unable to give input during if statement.

    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;
    }
Alex Lop.
  • 6,810
  • 1
  • 26
  • 45
  • 2
    Does this answer your question? [scanf() leaves the new line char in the buffer](https://stackoverflow.com/questions/5240789/scanf-leaves-the-new-line-char-in-the-buffer) – Alex Lop. Jun 16 '20 at 10:51

1 Answers1

0

Try this :

#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;
}
ZZZDamon
  • 34
  • 8