mercredi 9 décembre 2020

Simple C program using If statement stops running in VS Code

I made a simple C program to understand the working of If - Else statement but in VS Code the program stops at second input without any error prompt. Please tell me what's the problem with my program?

#include <stdio.h>

int main(){

    char math, sci;

    printf("Have you passed Mathematics test (y/n)\n");
    scanf("%c", &math);

    printf("Have you passed Science test (y/n)\n");
    scanf("%c", &sci);

    if ((math == 'y') && (sci == 'y'))
    {
        printf("You get a gift of worth Rs. 45.");
    }
    else if ((math == 'n') && (sci == 'y'))
    {
        printf("You get a gift of worth Rs. 15.");
    }
    else if ((math == 'y') && (sci == 'n'))
    {
        printf("You get a gift of worth Rs. 15.");
    }
    else if ((math == 'n') && (sci == 'n'))
    {
        printf("You don't get any gift.");
    }

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire