So I am trying to write a program that will tell you the lowest grade and the highest grade out of the 3 wthat you put in and also tell you the current average you have in the class. I got the lowest and highest part taken care of but I am having issues with it coming up with the current average you have in the class. It keeps giving me 0 as the average for the student and I can't find the mistake so I was hoping another set of eyes can help me out with this. Here is the program:

`#include <iostream>

using namespace std;

int main()

int midtermgrade, projectaverage, papergrade;

cout << "Please enter your midterm grade" << endl;

cin >> midtermgrade;

cout << "Please enter your project average" << endl;

cin >> projectaverage;

cout << "Please enter your paper grade" << endl;

cin >> papergrade;


    if ((midtermgrade > projectaverage) && (midtermgrade > papergrade))
    {
    cout<<"You highest grade is " <<midtermgrade << endl;
    }
        else if ((projectaverage > midtermgrade) && (projectaverage > papergrade))
    {
        cout<<"Your highest grade is " <<projectaverage << endl;
    }
        else if ((papergrade > projectaverage) && (papergrade > midtermgrade))
    {
        cout<<"Your highest grade is " <<papergrade << endl;
    }

    if ((midtermgrade < projectaverage) && (midtermgrade < papergrade))
    {
    cout<<"You lowest grade is " <<midtermgrade << endl;
    }
        else if ((projectaverage < midtermgrade) && (projectaverage < papergrade))
    {
        cout<<"Your lowest grade is " <<projectaverage << endl;
    }
        else if ((papergrade < projectaverage) && (papergrade < midtermgrade))
    {
        cout<<"Your lowest grade is " <<papergrade << endl;
    }
int paperweight, projectweight, midtermweight, currentaverage;
    paperweight=.25;
    projectweight=.3;
    midtermweight=.2;
    currentaverage = ((paperweight * papergrade) + (projectweight * projectaverage) + (midtermweight * midtermgrade));

    cout << "You current average is " <<currentaverage << endl; // trying to find the average but it keeps coming out as 0

return 0;

Hope someone can find my error and I am new to the C++ so any kind of feedback or advice is welcome.

You should be using floating point variables if you need precision below 0, otherwise all of your weights are going to be 0.

Okay so instead of doing just int (variable) I would do float (variable = value)?

Try using a vector like

vector<float> my_grades; // float = number with decimals
float grade1, grade2, grade3;

then write your question like

cout << "What is your first grade?; 
cin >> grade1; 

then push_back the cin like so:

my_grades.push_back(grade1); 

when you do this for all of your grades, you can then use the function

sort(my_grades.begin(), my_grades.end());

this will sort your grades from least to greatest.

from there you can do

float average = ( (my_grades.at(0) + my_grades.at(1) + my_grades.at(2)) / 3);
cout << "Average = " << average << endl;
Comments
Worthless idea

Another idea for finding the min and max grade:

Input midtermgrade
    set Min and Max to this grade (one of them *could* be true)
input projectaverage
    test with Min & Max and replace if necessary
input papergrade
    test with Min & Max and replace if necessary

This way you won't need the confusing IF statements you currently have.

This is not a problem, but a suggestion for making your code more reader-friendly.

Your variables names are quite self-explanatory which is good, but try camel-casing. For example

midtermgrade would look like midtermGrade.

This article has been dead for over six months. Start a new discussion instead.