Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- char q;
- int classes = 0;
- int i = 0;
- int units = 0;
- double unitsTotal = 0.0;
- double gradeTotal = 0.0;
- double gpa = 0.0;
- printf("Enter how many classes you have taken: ");
- scanf_s("%d", classes);
- printf("Enter your grades for each class and how many units each is worth.");
- while (i <= classes) {
- printf("Enter grade for course %d: ", i);
- q = getchar();
- if (q = 'a' || 'A')
- {
- printf("How many units for this course?");
- scanf_s("%d", units);
- unitsTotal = unitsTotal + units;
- gradeTotal = gradeTotal + (units * 4);
- i = i + 1;
- }
- else if (q = 'b' || 'B')
- {
- printf("How many units for this course?");
- scanf_s("%d", units);
- unitsTotal = unitsTotal + units;
- gradeTotal = gradeTotal + (units * 3);
- i = i + 1;
- }
- else if (q = 'c' || 'C')
- {
- printf("How many units for this course?");
- scanf_s("%d", units);
- unitsTotal = unitsTotal + units;
- gradeTotal = gradeTotal + (units * 2);
- i = i + 1;
- }
- else if (q = 'd' || 'D')
- {
- printf("How many units for this course?");
- scanf_s("%d", units);
- unitsTotal = unitsTotal + units;
- gradeTotal = gradeTotal + (units * 2);
- i = i + 1;
- }
- else if (q = 'f' || 'F')
- {
- printf("How many units for this course?");
- scanf_s("%d", units);
- unitsTotal = unitsTotal + units;
- gradeTotal = gradeTotal + (units * 0);
- i = i + 1;
- }
- else
- {
- printf("invalid grade.");
- }
- }
- gpa = gradeTotal / unitsTotal;
- printf("your gpa is %.2f", gpa);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement