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;
    cin>>g1;
    cout<<"enter a grade 0-100"<<endl;
    cin>>g2;
    cout<<"enter a grade 0-100"<<endl;
    cin>>g3;
    cout<<g1<<g2<<g3;
    system("PAUSE");
    return 0;
}
void in(double & S1, double & S2, double & S3)
{   cout<<"enter a grade"<<endl;
    cin>>S1;
    cout<<"enter a grade"<<endl;
    cin>>S2;
    cout<<"enter a grade"<<endl;
    cin>>S3;
    cout<<S1<<S2<<S3;
}
double ave(double & S1, double & S2, double & S3)
{   
    double PP;

    PP=S1+S2+S3;
    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;
}

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.

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!!

> 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?"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.