Creating a GPA Calculator on Your Own

  • Thread starter Thread starter TheDoorsOfMe
  • Start date Start date
  • Tags Tags
    Calculator Gpa
Click For Summary

Discussion Overview

The discussion revolves around creating a GPA calculator as a programming project. Participants are sharing code snippets and suggestions for implementing features such as inputting the number of classes, grades, and credits, as well as calculating the GPA based on these inputs.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant outlines their goal to create a GPA calculator for personal learning in programming, specifying the desired output format for user input.
  • Another participant provides a code snippet in C to loop through the number of classes and prompt for credits, suggesting a method to accumulate total credits.
  • A later reply critiques the initial code, noting it lacks prompts for grades and further calculations, and suggests a method for calculating GPA by multiplying credits by grades and keeping a running total.
  • Participants discuss the need for a loop to handle multiple classes and the importance of using appropriate data types for GPA calculations.

Areas of Agreement / Disagreement

There is no explicit consensus on the final implementation details, as participants are providing different suggestions and improvements to the initial code without resolving the overall approach.

Contextual Notes

The discussion includes various assumptions about how grades are represented and how calculations should be performed, which remain unresolved. The initial code does not account for grades or the complete GPA calculation process.

TheDoorsOfMe
Messages
46
Reaction score
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);

return 0;
}
 
Physics news on Phys.org
the is in C if that helps!
 
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;
}
 
thank you very much!
 
TheDoorsOfMe said:

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


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.
 
Last edited:

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K