# Homework Help: GPA Calc

1. Jul 11, 2009

### TheDoorsOfMe

1. The problem statement, all variables and given/known data

I wanna 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?

number of credits for class 1:

and so on...

What do I need to do to make the number of classses entered come up?

2. Relevant equations

3. 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);

return 0;
}
1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution

2. Jul 11, 2009

### TheDoorsOfMe

the is in C if that helps!

3. Jul 11, 2009

### nvn

Something like this.

int ii,total=0;
for(ii=1;ii<=classes;++ii){
printf("How many credits was class %d? ",ii);
scanf("%d",&credits);
total=total+credits;
}

4. Jul 12, 2009

### TheDoorsOfMe

thank you very much!

5. Jul 12, 2009

### Staff: Mentor

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.

Last edited: Jul 12, 2009