c program is not asking value at a scanf funtion, it just going forward without asking

Viewed 33

c program is not asking value at a scanf funtion, it just going forward without asking Here is my code....

#include <stdio.h>

int main() {

    float p, r, t, si;
    char A;

    printf("Principle Amount : ");
    scanf("%f", &p);

    printf("Rate of Intrest : ");
    scanf("%f", &r);

    printf("Time Period : ");
    scanf("%f", &t);

    si = ( p * r * t ) / 100;

    printf("Simple Intrest = %.2f \n", si);
    
    printf("Do you want to know the incremented amount ?\n");
    printf("Y for yes & N for no : ");
    scanf("%c", &A);

    if (A == 'Y') {
        printf("Incremented amount will be = %f", p + si);
    }
    else if (A == 'N') {
        printf("Thank You 4 using :-) ");
    }
    else {
        printf("INVALID INPUT");
    }
    return 0;
}

Log:

Principle Amount : 10000
Rate of Intrest : 5
Time Period : 2
Simple Intrest = 1000.00 
Do you want to know the incremented amount ?
Y for yes & N for no : INVALID INPUT  

It should ask me Y or N after "Y for yes & N for no : ", but it is abruptly taking the else condition.

0 Answers
Related