Well,It also gives me an error.
every where when you have else statements coming ahead of else if statements.
May be we can alter the structure of the program , if suppose you have a candidate getting less than 35, you still get into the if block
here and check for grades.
I also don't under the rationale behind the statements like
printf("\nyou don't get A-,%f",Total);
.
.
printf("\nyou don't get B,%f",Total);
.
.
printf("\nyou don't get C+,%f",Total);
I would rather care for my grades than "you don't get" thing.
1st approach:
I would rather have a huge if block which checks whether the toal is greater than 35 and then calculate the grades.
const int MINIMUM_PASS_MARKS = 35;
if (total >= MINIMUM_PASS_MARKS) {
/* and then go on checking for a valid grade*/
}
else {
/* failed*/
}
Option 2 :
Well ,you have a set grade for any given marks and a definite increment (5 in your case), So we make an array which holds
marks[] and another array which hold your grades[],it would make things simpler.
Something like this
#include<stdio.h>
int main(void) {
const int MAX_MARKS = 100;
const int mark_range[] = {80, 75, 70, 65, 60, 55, 50, 45, 40, 35};
const char *grades[] = {"A", "A-", "B+", "B", "B-","C+", "C", "C-",
"D+", "D"};
int total = 0;
int i = 0;
int divisons = sizeof (mark_range) / sizeof mark_range[0];
int passed = 0; /*let 0 represent fail*/
printf("Enter your total ");
if (scanf("%d", &total) == 1) {
printf("Your total is %d", total);
/*Loop through to get your grade*/
for ( i = 0; i < divisons; i++) {
if (total >= mark_range[i] && total <= MAX_MARKS) {
printf("\nYour grade is %s",grades[i]);
passed = 1;
break;
}
}
if (passed == 0)
printf("\nSorry, you failed.");
}
else
fprintf(stderr, "Error in input");
return 0;
}
Give them a rude shock if someone enters marks > 100

and we don't use non standard headers (aka conio.h and the getch() function)