The Average Of Three grades

I need help with my program.I have already started it but can't finish the program.The user is to input three grades and find the average of these three grades.


#include <iostream>

using namespace std;

int main()
{


double Average, grade=0, grade1=0, grade2=0, grade3=0;




{


cout<<"Please Enter Grade #1"<<endl;
cin >> grade1 ;
cout<<"Please Enter Grade #2"<<endl;
cin >> grade2 ;
cout<<"Please Enter Grade #3"<<endl;
cin>> grade3 ;

{
if (grade >=90)
cout<< "Congrats your average is: You got an A "<<endl;

}

{
if (grade <=90)
cout<< "Your average is: You got an B "<<endl;

}

{
if (grade >=70 && grade <=80)
std::cout<< "Your average is: You got an C "<<endl;

}



{
if (grade <70)
cout<< "Sorry, your average is: You got an F "<<endl;

}


Average = (grade1+grade2+grade3)/3;

cout<<Average<<endl;





return 0;
}
The user is to input three grades and find the average of these three grades.

Then all you need is something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main()
{
    double grade1=0, grade2=0, grade3=0;

    cout << "Please Enter Grade #1" << endl;
    cin  >> grade1 ;

    cout << "Please Enter Grade #2" << endl;
    cin  >> grade2 ;

    cout << "Please Enter Grade #3" << endl;
    cin  >> grade3 ;

    double Average = (grade1+grade2+grade3)/3;

    cout<< "Your average is: " << Average << endl;

    return 0;
} 


The original program has a lot of additional code, but it is all based around the variable named grade which is always zero. Perhaps you meant to use the Average there?

I found some ambiguities in the way you represent the scores (if the student scores 90, he gets an A and a B at the same time?) The code below seems to be a little better:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>

using namespace std;

int main ()
{
	double grade(0.0), grade1(0.0), grade2(0.0), grade3(0.0);

	cout<<"Please Enter Grade #1"<<endl;
	cin >> grade1 ;
	cout<<"Please Enter Grade #2"<<endl;
	cin >> grade2 ;
	cout<<"Please Enter Grade #3"<<endl;
	cin>> grade3 ;

	grade = (grade1+grade2+grade3)/3;

	if (grade>=90)
		cout << "Congrats, your average is: " << grade << ". You got an A" << endl;
	else if (grade<90 && grade>=80)
		cout << "Congrats, your average is: " << grade << ". You got an B" << endl;
	else if (grade<80 && grade>=70)
		cout << "Congrats, your average is: " << grade << ". You got an C" << endl;
	else
		cout << "Sorry, your average is: " << grade << ". You got an F" << endl;

	return 0;
}
Topic archived. No new replies allowed.