i am a beginner in C programming. I was learning about the user inputs. The following piece of code:
    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
        char grade;
        printf("Enter you grade: ");
        scanf("%c", &grade);
        printf("Your grade is %c.", grade);
        return 0;
     }
does what I intend it to do i.e.
- ask for the grade
- display the grade
But when I modify the code to the following :
     #include <stdio.h>
     #include <stdlib.h>
     int main()
    {
           int age;
           printf("Enter you age: ");
           scanf("%d", &age);  
           printf("You are %d years old.\n", age);
           printf("-----------------------------\n");
           double gpa;
           printf("Enter your GPA: ");
           scanf("%lf", &gpa);
           printf("Your GPA is %f. \n", gpa);
           printf("-----------------------------\n");
           char grade;
           printf("Enter you grade: ");
           scanf("%c", &grade);
           printf("Your grade is %c.", grade);
           return 0;
     }
it does the following:
- asks for the age
- displays the age
- asks for the gpa
- displays gpa
- asks for grade
- it doesnt display grade.
The output looks like:
Enter you age: 45 You are 45 years old. ----------------------------- Enter your GPA: 4 Your GPA is 4.000000. ----------------------------- Enter you grade: Your grade is .
please suggest me what I am doing wrong.
 
    