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
In your switch statement you are checking the value of
Grading
, butscanf
writes its output inrate
.You should change your switch case like so:
Use
&Grading
instead of&rate
Or
Declare
char rate
instead ofGrading
You have declared
Grading
andscanf
usesrate