Welcome to TRiBot Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0
Jaybots1

All coders please read

12 posts in this topic

I was assigned to write a program that calculates the GPA of 5 classes.

 

Have I made any errors? Would it run successfully? Want your guys input before I submit this. 

 

// Program Greeting

 prompt "Calculate your GPA of five classes."

 prompt "The only acceptable answers are A, B, C, D, F."

 

// Input

 prompt "Enter grade 1" into G1

 prompt "Enter grade 2" into G2

 prompt "Enter grade 3" into G3

 prompt "Enter grade 4" into G4

 prompt "Enter grade 5" into G5

 

// Process

 A=4

 B=3

 C=2

 D=1

 F=0 

 GPA=(G1+G2+G3+G4+G5) % 5

 

// Output

 display GPA 

 

Share this post


Link to post
Share on other sites

How are you supposed to be calculating GPA? Just taking the average of the 5 grades?

Share this post


Link to post
Share on other sites

How are you supposed to be calculating GPA? Just taking the average of the 5 grades?

 

I think it also depends how many units/credits a course is.

 

A 2 unit course won't have the same effect on your GPA as a 3 unit course for example

Share this post


Link to post
Share on other sites

I think it also depends how many units/credits a course is.

 

A 2 unit course won't have the same effect on your GPA as a 3 unit course for example

I should have made it clear, the professor told us not to worry about units.

Share this post


Link to post
Share on other sites

I'm from the UK, so I am not familiar with GPA scores. But if you're obtaining the wrong output with the code you have supplied, could it possibly be because you're using a modulo operator (%) instead of a division operator?

Edit: I just reread it, pseudocode. I don't know then. Sorry!

Edited by GrandMasterFrillz

Share this post


Link to post
Share on other sites

I'm from the UK, so I am not familiar with GPA scores. But if you're obtaining the wrong output with the code you have supplied, could it possibly be because you're using a modulo operator (%) instead of an division operator?

 

It very well could be. 

 

We just learned about the mod today in class, then he gave us this assignment so I assumed the calculation of the GPA would use the mod.

 

The way to calculate GPA in the US is:

 

Points / Units = GPA

Share this post


Link to post
Share on other sites

How are you supposed to be calculating GPA? Just taking the average of the 5 grades?

Yes, just looking to find the average. New to coding, 2nd week in college

Share this post


Link to post
Share on other sites

Yes, just looking to find the average. New to coding, 2nd week in college

The % operator doesn't do what you think it does. % is called the modulus operator; it returns the remainder. For example, 3 % 2 = 1.

You want to divide by 5. / is the division operator.

(4+3+2+3+4) % 5 = 1

(4+3+2+3+4) / 5 = 3.2

2 people like this

Share this post


Link to post
Share on other sites

It very well could be. 

 

We just learned about the mod today in class, then he gave us this assignment so I assumed the calculation of the GPA would use the mod.

 

The way to calculate GPA in the US is:

 

Points / Units = GPA

Assuming the GPA is just the average of the total points for each unit, divided by the number of units:

GPA = Summation(units) / count(units)

Use a divide operator rather than a mod operator.

"The modulo operation finds the remainder after division" - Wikipedia.

https://en.wikipedia.org/wiki/Modulo_operation

Modulo operators are useful for anything that is cyclic in nature (you'll probably end up using them within loops at some point), or if you want to check if a number is even or odd, some example pseudocode:

x = some number.IFF x % 2 == 0 THEN  print 'x is even'ELSE  print 'x is odd'
Edited by GrandMasterFrillz

Share this post


Link to post
Share on other sites

couldn't you just use a double and force it to use 1 demical point, the modulus just makes it seem more complicated than it should be 

Share this post


Link to post
Share on other sites

couldn't you just use a double and force it to use 1 demical point, the modulus just makes it seem more complicated than it should be 

Modulo isn't going to help calculate the average in anyway whatsoever.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.