To create a GPA calculator, the program should prompt the user for the number of classes and the corresponding grades and credits for each class. The initial code correctly asks for the number of classes and credits but lacks the logic to calculate the GPA. A loop is necessary to gather input for each class and compute the total grade points by multiplying credits by grades. After processing all classes, the total grade points should be divided by the total credits to yield the GPA. Implementing these changes will enhance the functionality of the GPA calculator project.
#1
TheDoorsOfMe
46
0
Homework Statement
I want to create a gpa calculator. This isn't for school I am just trying to learn some programming on my own and came up with this project.
I want the output to be something like this:
how many classes have you taken?
grade for class 1:
number of credits for class 1:
and so on...
What do I need to do to make the number of classses entered come up?
Homework Equations
The Attempt at a Solution
#include <stdio.h>
#include <stdlib.h>
#define a 4
#define b 3
#define c 2
#define d 1
#define f 0
int main(void)
{
int classes;
int credits;
printf("How Many Classes did you take? ");
scanf("%d", &classes);
printf("How Many credits was class 1: ");
scanf("%d", &credits);
I want to create a gpa calculator. This isn't for school I am just trying to learn some programming on my own and came up with this project.
I want the output to be something like this:
how many classes have you taken?
grade for class 1:
number of credits for class 1:
and so on...
What do I need to do to make the number of classses entered come up?
Homework Equations
The Attempt at a Solution
Code:
#include <stdio.h>
#include <stdlib.h>
#define a 4
#define b 3
#define c 2
#define d 1
#define f 0
int main(void)
{
int classes;
int credits;
printf("How Many Classes did you take? ");
scanf("%d", &classes);
printf("How Many credits was class 1: ");
scanf("%d", &credits);
return 0;
}
Your code above (that I formatted with code tags) looks like it would compile just fine, but wouldn't do anything useful. Your code prompts for the number of classes, and then sets you classes variable with the number you enter. The code then prompts for the number of credits of class 1, and then sets the credits variable for that class.
The code doesn't prompt for the grade for class 1 (or any other classes), and doesn't do any further calculations. The last thing it does is return 0.
What the code should do is this: for each class, multiply the number of credits by the grade, and keep a running total of these values. When you have cycled through all of the classes, divide by the number of credits to get the GPA.
For example, if your classes were 5 credits, 4 credits, and 5 credits, and the respective grades were B, A, and B, you program should have a total points value of 15, then 15 + 16 = 31, then 31 + 14 = 45.
The total number of credits is 14, so the GPA would be 45/14 = 3.214286 (approx.). Since the GPA is a decimal number, you should use either float or double to store this value.
Since there are (potentially) multiple classes, you will need to use a loop of some kind to input the information and calculate the running totals for each class.