Go Back   Flash Flash Revolution > General Discussion > Technology
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 01-30-2014, 10:10 AM   #1
DossarLX ODI
Batch Manager
Game Manager, Song Release Coordinator
Game ManagerSimfile JudgeFFR Simfile AuthorD7 Elite KeysmasherFFR Veteran
 
DossarLX ODI's Avatar
 
Join Date: Mar 2008
Location: USA
Age: 29
Posts: 14,859
Default C++ calculation and character issue

I just started getting into C++; this is a simple assignment but there's something about calculations and even a character issue here that I can't figure out.

The catch of the assignment is to input quiz grades for a student, input the weight the quiz has on the total grade, calculate the student's final grade by getting the average, and then assigning a letter grade (this is the character part).


Code:
class Student
{
    
public:           
    void input();
    void output();	

private:
    int qgrade[4]; // Each array cell indicates the quiz number's grade.
    int qweight[4]; // Each array cell indicates the quiz number's weight.
    // 0 for quiz1, 1 for quiz2, 2 for midterm, 3 for final exam.
    double avweight;
    char lettergrade;

    double calc_ave();
    char calc_letter();

};


My input function also calls the calc_ave and calc_letter functions to assign a letter grade and final average for that student. The inputs themselves work, but then I have these lines of code and this is when things get screwy.

Student::avweight = calc_ave();
Student::lettergrade = calc_letter();

avweight comes out to be something stupid like 2800 or something, and then lettergrade just doesn't appear at all (it's a blank space where there should be a letter). I'll show the functions so I can make any appropriate corrections concerning what may have gone wrong.


Code:
double Student::calc_ave(){
    
    int i;
    double total = 0.0;
    for ( i = 0 ; i < 4 ; i++ )
    {
        total += (double)( Student::qgrade[i] * Student::qweight[i] );
    }
    return total;
}



Code:
char Student::calc_letter(){
    double avgrade = Student::avweight;
    char lgrade; // For storing the letter grade to return
    if( avgrade < 65.0 )
        lgrade = 'F';
    else if( avgrade >= 65.0 && avgrade < 70.0 )
        lgrade = 'D';
    else if( avgrade >= 70.0 && avgrade < 80.0 )
        lgrade = 'C';
    else if( avgrade >= 80.0 && avgrade < 90.0 )
        lgrade = 'B';
    else if( avgrade >= 90.0 && avgrade <= 100.0 )
        lgrade = 'A';
    return lgrade;
}


So basically the inputs for the student work, but when I call the calc_ave and calc_letter functions, I print out the values and the letter grade comes up as a blank space while calc_ave gives some number that is way off.

EDIT: Here's sample output to show what I'm talking about

Code:
Please input student 1's grades.
Grades and weight should be input out of 100.
Input grade for quiz #1: 80
Input weight for quiz #1: 20
You entered 80 and 20
Input grade for quiz #2: 70
Input weight for quiz #2: 20
You entered 70 and 20
Input grade for midterm exam: 60
Input weight for midterm exam: 25
You entered 60 and 25
Input grade for final exam: 75
Input weight for final exam: 35
You entered 75 and 35
7125Average weight.
  letter grade.
Student 1's grades successfully entered.

Student Grade Evaluator
This program enters grades for 3 students and calculates them.
0 - Quit Program
1 - Input Grades
2 - Output Grades
Please select an item from the menu list: 2
Student 1's grades are:
Quiz 1: 80
Quiz 2: 70
Miderm Exam: 60
Final Exam: 75
This student scored 7125 and got a  for the course.
80 x .2
70 x .2
60 x .25
75 x .35

16 + 14 + 15 + 26.25 = 71.25

It should say the student got a grade of 71.25 and a letter grade of C, but that's not what's happening here.
__________________
Quote:
Originally Posted by hi19hi19 View Post
oh boy, it's STIFF, I'll stretch before I sit down at the computer so not I'm not as STIFF next time I step a file

Last edited by DossarLX ODI; 01-30-2014 at 10:20 AM..
DossarLX ODI is offline   Reply With Quote
Old 01-30-2014, 10:24 AM   #2
arcnmx
nanodesu~
Retired StaffFFR Veteran
 
arcnmx's Avatar
 
Join Date: Jan 2013
Location: Ontario, Canada
Posts: 503
Send a message via Skype™ to arcnmx
Default Re: C++ calculation and character issue

Quote:
Originally Posted by DossarLX ODI View Post
Input grade for quiz #1: 80
Input weight for quiz #1: 20
total += (double)( Student::qgrade[i] * Student::qweight[i] );
Your types are integers, so that would be doing 80*20 rather than 80*0.2

Your letter isn't appearing since the grade is over 100, and you don't assign anything to lgrade in that case (so it'll default to junk / a meaningless character).
__________________


FMO AAAs (1): Within Life :: FGO AAAs (1): Einstein-Rosen Bridge

Last edited by arcnmx; 01-30-2014 at 10:28 AM..
arcnmx is offline   Reply With Quote
Old 01-30-2014, 10:26 AM   #3
DossarLX ODI
Batch Manager
Game Manager, Song Release Coordinator
Game ManagerSimfile JudgeFFR Simfile AuthorD7 Elite KeysmasherFFR Veteran
 
DossarLX ODI's Avatar
 
Join Date: Mar 2008
Location: USA
Age: 29
Posts: 14,859
Default Re: C++ calculation and character issue

Ok, so I asked the weights to be entered as integers. I forgot to divide by 100.0 when multiplying them in the calc_ave function.

Since the numbers were too large, it went out of the boundaries of the calc_letter numbers. Thanks arcnmx! I'll test it out again.

Edit: That works. I thought I somehow didn't get the character assignment syntax correct or something. I was getting junk values before I assigned sizes to the arrays as well.
__________________
Quote:
Originally Posted by hi19hi19 View Post
oh boy, it's STIFF, I'll stretch before I sit down at the computer so not I'm not as STIFF next time I step a file

Last edited by DossarLX ODI; 01-30-2014 at 10:33 AM..
DossarLX ODI is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 11:25 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution