hello:
I have to write a program that calculates a student's term GPA.
inputs- the letter grade and the credits for each course.
but , the letter grade has two character the letter and the suffix ex. B+, i'm not sure how to enter these two characters. Also , I have to add 1/3 or subtract 1/3 depending on the suffix.
the specific requirements are to use a sentinel-terminated while loop, at least one switch statement and if-else statements.
Any number of grades may be entered, ending with a sentinel 0 for the course credits.
i tried testing it and it said "unexpected end of file while looking for precompiled header directive ??? what does it mean?
this is what i have so far, please help!!
Code:#include "stdio.h" /* printf and scanf definitions */ #define SENTINEL 0 /* value for the program to terminate */ int main() { char grade; /* input-letter grade per class */ char suffix; /* input-suffix of the letter grade, if any */ int credits=0; /* credits per class */ int sumcredits=0; /* total credits for the term */ double classGPA=0; /* gpa of a single class */ double termGPA=0; /* output-gpa of the term */ /* Get grade and credits */ printf("Enter first grade and corresponding credits or %d to finish > ", SENTINEL); scanf("%c%c %d", &grade, &suffix, &credits); while !(grade == SENTINEL && credits == SENTINEL) { switch (grade) { case:'a' case:'A' grade=4;break; case:'b' case:'B' grade=3;break; case:'c' case:'C' grade=2;break; case:'d' case:'D' grade=1;break; default printf("GPA cannot be calculated with the grade entered"); break; } if(suffix == '+') grade = grade + (1/3); else if(suffix == '-') grade = grade - (1/3); else grade = grade; classGPA = (classGPA)* credits; sumcredits = sumcredits + credits; } termGPA = classGPA / sumcredits; printf(" the student's GPA for the term is %.3f \n", termGPA); return 0; }![]()



LinkBack URL
About LinkBacks



