skip to Main Content
printf("On a scale of (A - F) rate your experience with our Consortium's HR Departmentnn");
char Grading;
    printf("nEnter a grade: nn");
    scanf("%c", &rate);

    switch (Grading) {
    case 'A':
        printf("Perfect!nn");
        break;
        case 'B':
        printf("You did good!nn");
        break;
    case 'C':
        printf("You did okaynn");
        break;
    case 'D':
        printf("At least not badnn");
        break;
    case 'E':
        printf("Badnn");
        break;
    case 'F':
        printf("Awfulnn");
        break;
    default:
        printf("Please enter only valid gradesnn");
        
}
return 0;
}

This is just the section i need help with in my codeblocks. Doing this separately on a different visual studio tab works, but together with my previous codes;it keeps saying enter only valid grades

I tried making a grading on C. My code actually works, i mean that exact grading code block works on a different tab. But when added to my previous code, the project ima working on, it keeps saying enter only valid grades. Ima kinda asking if there’s a finna conventional method of adding the C grading block to a project in C

2

Answers


  1. In your switch statement you are checking the value of Grading, but scanf writes its output in rate.

    You should change your switch case like so:

    printf("On a scale of (A - F) rate your experience with our Consortium's HR Departmentnn");
    char rate; //rename Grading to rate
        printf("nEnter a grade: nn");
        scanf("%c", &rate);
    
        switch (rate) { //rename Grading to rate
        case 'A':
            printf("Perfect!nn");
            break;
            case 'B':
            printf("You did good!nn");
            break;
        case 'C':
            printf("You did okaynn");
            break;
        case 'D':
            printf("At least not badnn");
            break;
        case 'E':
            printf("Badnn");
            break;
        case 'F':
            printf("Awfulnn");
            break;
        default:
            printf("Please enter only valid gradesnn");
            
    }
    return 0;
    }
    
    Login or Signup to reply.
  2. Use &Grading instead of &rate

    Or

    Declare char rate instead of Grading

    You have declared Grading and scanf uses rate

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search