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;

cin >> projectaverage;

{
}
{
}
{
}

{
}
{
}
{
}
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)?

That would be a good start.

Ok awesome! Thanks!

Try using a vector like

``````vector<float> my_grades; // float = number with decimals
``````

``````cout << "What is your first grade?;
``````

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());
``````

from there you can do

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

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
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`.

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.