01-30-2014, 10:10 AM | #1 |
Batch Manager
Game Manager, Song Release Coordinator
Join Date: Mar 2008
Location: USA
Age: 29
Posts: 14,859
|
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). 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. 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
__________________
Last edited by DossarLX ODI; 01-30-2014 at 10:20 AM.. |
01-30-2014, 10:24 AM | #2 | |
nanodesu~
|
Re: C++ calculation and character issue
Quote:
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.. |
|
01-30-2014, 10:26 AM | #3 |
Batch Manager
Game Manager, Song Release Coordinator
Join Date: Mar 2008
Location: USA
Age: 29
Posts: 14,859
|
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.
__________________
Last edited by DossarLX ODI; 01-30-2014 at 10:33 AM.. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|