When using the variable from float grade that is equal to sometimes the start of the range or the end of the range, skips to else statement. Also when scanning a negative number, discards the unary sign and acts as a positive.
Sample input 1: 3.8 expected result: Excellent outcome: Average
Sample input 2: 1.3 expected result: Passing outcome: Invalid input...
Grade | Description |
---|---|
3.8 - 4.0 | Excellent |
3.3 - 3.7 | Superior |
2.8 - 3.2 | Good |
1.8 - 2.7 | Average |
1.3 - 1.7 | Below Average |
1.0 - 1.2 | Passing |
below 1.0 | Failure |
not within 0.0 - 4.0 | Invalid |
#include<stdio.h>
int main (void){
float grade;
printf("\t\tWhat is your grade?\t\t");
scanf("%f",&grade);
if ((grade<=4.0) && (grade>=3.8)){
printf("\n\t\tInput grade: %.1f",grade);
printf("\n\t\tExcellent");
}
else if ((grade<=3.7) && (grade>=3.3)){
printf("\n\t\tInput grade: %.1f",grade);
printf("\n\t\tSuperior");
}
else if ((grade<=3.2) && (grade>=2.8)){
printf("\n\t\tInput grade: %.1f",grade);
printf("\n\t\tGood");
}
else if ((grade<=3.7) && (grade>=1.8)){
printf("\n\t\tInput grade: %.1f",grade);
printf("\n\t\tAverage");
}
else if ((grade<=1.7) && (grade>=1.3)){
printf("\n\t\tInput grade: %.1f",grade);
printf("\n\t\tBelow Average");
}
else if ((grade<=1.2) && (grade>=1.0)){
printf("\n\t\tInput grade: %.1f",grade);
printf("\n\t\tPassing");
}
else if ((grade<=1.0) && (grade>=0)){
printf("\n\t\tInput grade: %.1f",grade);
printf("\n\t\tFailure");
}
else{
printf("\n\t\tInvalid input...");
}
return 0;
}