I am still just a beginner and i made this average program. It worked out just fine. THen i decided I wanted to make it say like the grade you got such as an A+ or C. Anyway after I add all the grades and divide them by the number of grades I want to store the average as a variable "average" and then use the if/else statements. Any help will be appreciated.

#include <iostream>
using namespace std;

int main()
{
    system("TITLE Averager");
    system("COLOR 2f");
    int gradea;
    int gradeb;
    int gradec;
    int graded;
    int gradee;    
    int gradef;
    int average;
    
    cout<<"Please input your 5 test grades for an average\n";
    
    cout<<"Please input your first test grade: ";
    cin>>gradea;
    
    cout<<"Please input your second test grade:";
    cin>>gradeb;
    
    cout<<"Please input your third test grade: ";
    cin>>gradec;
    
    cout<<"Please input your fourth test grade: ";
    cin>>graded;
    
    cout<<"Please input your fifth test grade: ";
    cin>>gradee;
    
    cout<<"Please input your sixth test grade: ";
    cin>>gradef;
    
    cout<<"Your average grade is: "<<(gradea + gradeb + gradec + graded + gradee + gradef)/6<<endl;
    
    if ( > 97.5)
    cout<<"You got an A+";
    
    system("pause");
    return 0;
}

So what's the problem? (besides your bad code)

I know my code is bad however my problem is that after i average the grades i want to store that average as a variable. Ive tried doing (gradea + gradeb + gradec + graded + gradee + gradef)/6= average and cin>>average but i cant it doesnt work. Any alternatives??

cout<<"Your average grade is: "<<(gradea + gradeb + gradec + graded + gradee + gradef)/6<<endl;
if ( > 97.5)
cout<<"You got an A+";

try this

int average;
average = (gradea + gradeb + gradec + graded + gradee + gradef)/6;
cout << "Your average grade is: "<< average << endl;
 if (average  > 97.5)
    cout<<"You got an A+";

Good Luck!

I know my code is bad however my problem is that after i average the grades i want to store that average as a variable. Ive tried doing (gradea + gradeb + gradec + graded + gradee + gradef)/6= average and cin>>average but i cant it doesnt work. Any alternatives??

Basic rule: Left Hand Side (LHS) is assigned the Right Hand Side (RHS). So, your average computation must be

average = (gradea + gradeb + gradec + graded + gradee + gradef)/6;

Further, since your grades and you divisor are all of type int, the result of the division will be of type int. You will not get a fractional value. Change the divisor to 6.0, and you will get a fractional value. Variable average must be declared as a floating point type, either float or double.

Now that you have an average, your statement to display the grade:

if ( > 97.5)
    cout<<"You got an A+";

can be corrected. As it stands, what is being compared to 97.5? Your compiler should have given an error on that line. Pay attention to the error and warning messages.

Val

Thanks that helped a lot

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.