Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Xqzrt
    New Member
    • Oct 2006
    • 3

    #1

    Question

    I am attempting to make a GPA calculator for a school project.
    I ask the user for their letter grade, whether the class is weighted or not and if the letter grade was a + or regular grade (A+ or A). The scale is from 4 to 0. If the class is weighted, the scale is from 5 to 1. If the grade received was an + grade (A+/B+/etc.), it adds 0.5 to the grade.

    In order to find the number of points from a class, I used the following formula:
    totalPointsFrom ClassOne=(1*wei ghtedScoreForOn e)+(0.5*plusGra deForOne)+int(c lassOneGrade);

    When I tested it (weighted A+), the answer should have been 5.5; however, I got the answer 98.5. I assigned A as 4, B as 3, C as 2, D as 1 and F as 0. I think it's having trouble converting the user input (the letter grade) and converting it to the assigned number. Can someone please help me solve this problem?


    I am a beginner, if you haven't noticed =P.
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    bool weighted = true if the grade is weighted
    bool plus = true if an A+, B+, etc, is received.
    char letter = 'A' for A/A+, 'B' for B/B+, etc.

    Code:
    grade = 0;
    if(weighted)
      grade++;
    
    grade += 4 - (letter - 'A');
    if(plus)
    grade += 0.5;
    
    cout << grade << endl;

    Comment

    Working...