Got a code failiure. I tried making a code that does this. Grade calculator. Assume max points are 300. make the user submit 3 numbers between 0-100 and have them added together and divided by 300 to get a decimal to the possible nearest Hundredth or whole number. 3 numbers are basically grades of the 0-100 points.

I don't expect anyone to be on this late, and I have an entire 3 days left for this code.

I use Dev-Cpp Bloodshed

My code fails by

Ex: 1st grade 15, 2nd 15, 3rd 15. add together gets 45. then divide by 300 should get .15. but what i get with my code is 151515Press any key to continue . . .

My code is this

//Michael Nicodemus
//Ch2 Program
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;

void in(double & S1, double & S2, double & S3);
double ave(double & S1, double & S2, double & S3, double & PP);
int out(int S1, int S2, int S3, double Grade);

int main()
{   double g1, g2, g3;
    cout<<"enter a grade 0-100"<<endl;
    cout<<"enter a grade 0-100"<<endl;
    cout<<"enter a grade 0-100"<<endl;
    return 0;
void in(double & S1, double & S2, double & S3)
{   cout<<"enter a grade"<<endl;
    cout<<"enter a grade"<<endl;
    cout<<"enter a grade"<<endl;
double ave(double & S1, double & S2, double & S3)
    double PP;

    return (PP);
int out(int S1, int S2, int S3, double Grade)
{   Grade=(S1+S2+S3)/300;
    return (Grade);
    cout<<"Your grade is"<<Grade<<endl;

Edited by Nickod777: n/a

6 Years
Discussion Span
Last Post by Ezzaral

You're not calling your functions anywhere within main(). It's simply outputting your input all in a row, as that's all you've asked it to do.

You need to name your functions better. Ave is finding a sum, and out is finding the average. That's confusing to anyone trying to read your code (especially your professor).

Your other functions operate on doubles. Since S1,S2,S3 are being passed in as integers in the "out" function, if you pass in a double value, it's going to be truncated down to an integer, so 16.4 would become 16, etc. To make matters worse, on line 42, you're summing 3 integers and dividing by an integer, which no matter what type "Grade" is, you'll get an integer response. So for S1+S2+S3 < 300, you'll get zero for a grade.

Edited by jonsca: n/a


I have to ask u what a professor is seriously!!? And my teacher gave a different format so I solved it anyway based on how the format was. The old format made no sense to his/her specifications.
I am in 6th grade with an age I messed up if signup needed an age, don't remember anymore.

So Goodbye and I may as well try and figure out how to mark this as answered.

edit: Not sure how to flag as answered!!

Edited by Nickod777: there's always a reason isn't there.


> Not sure how to flag as answered!!
Just click the link "Mark this thread as solved" at the bottom where it says "Has this thread been answered?"

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.