please help with hw

here is my code
ok so when I enter in 87 for all 3 grades and I mention that the person has perfect attendance, it curves the grade and gives him an A. But when I enter in 77 and give him perfect attendance, it doesn't give him a curve, it stays the same and gives him a c.


#include "stdafx.h" // Needed for Visual C++ Express 2010
#include <iostream>
using namespace std;
int main()
{
float grade1= 77, grade2=77, grade3= 77, average;
int numgrades= 3;
bool perfectattendance;
perfectattendance= 1;
average = (grade1 + grade2 + grade3) /numgrades;
cout << "Grade1=77" << endl;
cout << "Grade2=77" << endl;
cout << "Grade3=77" << endl;
cout << "Your grade is:" << average << endl;

if (average >= 90)
{
cout << "Your letter grade is an A" << endl;
}
else if ((average >= 80) && (average >= 87) && (perfectattendance==1))
{
cout << "Your letter grade is an A" << endl;
}
else if ((average >= 80) && (average >= 87) && (perfectattendance==0))
{
cout << "Yourletter grade is a B" << endl;
}
else if ((average >= 70) && (average < 77) && (perfectattendance==1))
{
cout << "Your letter grade is a B" << endl;
}
else if ((average >= 70) && (average >= 77) && (perfectattendance==0))
{
cout << "Your letter grade is a C" << endl;
}
else if ((average >= 60) && (average < 67) && (perfectattendance==1))
{
cout << "Your letter grade is a C" << endl;
}
else if ((average >= 60) && (average < 67) && (perfectattendance==0))
{
cout << "Your letter grade is a D" << endl;
}
else if ((average >= 50) && (average < 57) && (perfectattendance==1))
{
cout << "Your letter grade is a D" << endl;
}
else if ((average >= 50) && (average < 57) && (perfectattendance==0))
{
cout << "Your letter grade is an F and you failed the class" << endl;
}
cin.ignore(); // needed for Visual C++ Express 2010


return 0;
}
Your code explains everything. You have used if else statements to check the range of the average grade and if it is between 90 and 100, you give him an A, if between 80 and 87, you give him an A and so on.

Notice that the average you calculated is 77, which lies between 70 and 77, and so will give a grade C.
1
2
3
4
else if ((average >= 70) && (average >= 77) && (perfectattendance==0))
{
cout << "Your letter grade is a C" << endl;
}


Hope that helps.
@sl227

These are not correct.
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
29
30
31
32
33
34
35
36
if (average >= 90)
{
cout << "Your letter grade is an A" << endl;
}
else if ((average >= 80) && (average >= 87) && (perfectattendance==1))
{
cout << "Your letter grade is an A" << endl;
}
else if ((average >= 80) && (average >= 87) && (perfectattendance==0))
{
cout << "Yourletter grade is a B" << endl;
}
else if ((average >= 70) && (average < 77) && (perfectattendance==1))
{
cout << "Your letter grade is a B" << endl;
}
else if ((average >= 70) && (average >= 77) && (perfectattendance==0))
{
cout << "Your letter grade is a C" << endl;
}
else if ((average >= 60) && (average < 67) && (perfectattendance==1))
{
cout << "Your letter grade is a C" << endl;
}
else if ((average >= 60) && (average < 67) && (perfectattendance==0))
{
cout << "Your letter grade is a D" << endl;
}
else if ((average >= 50) && (average < 57) && (perfectattendance==1))
{
cout << "Your letter grade is a D" << endl;
}
else if ((average >= 50) && (average < 57) && (perfectattendance==0))
{
cout << "Your letter grade is an F and you failed the class" << endl;
}


They should be..
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
29
30
31
32
33
34
35
36
if (average >= 90)
{
cout << "Your letter grade is an A" << endl;
}
else if ((average >= 80) && (average <= 87) && (perfectattendance==1))
{
cout << "Your letter grade is an A" << endl;
}
else if ((average >= 80) && (average <= 87) && (perfectattendance==0))
{
cout << "Your letter grade is a B" << endl;
}
else if ((average >= 70) && (average < 77) && (perfectattendance==1))
{
cout << "Your letter grade is a B" << endl;
}
else if ((average >= 70) && (average <= 77) && (perfectattendance==0))
{
cout << "Your letter grade is a C" << endl;
}
else if ((average >= 60) && (average < 67) && (perfectattendance==1))
{
cout << "Your letter grade is a C" << endl;
}
else if ((average >= 60) && (average < 67) && (perfectattendance==0))
{
cout << "Your letter grade is a D" << endl;
}
else if ((average >= 50) && (average < 57) && (perfectattendance==1))
{
cout << "Your letter grade is a D" << endl;
}
else if ((average >= 50) && (average < 57) && (perfectattendance==0))
{
cout << "Your letter grade is an F and you failed the class" << endl;
}


Just small, in-attention, mistakes.
when average equals 77 and perfectattendance is true you would expect this line to execute

else if ((average >= 70) && (average < 77) && (perfectattendance==1))cout << "Your letter grade is a B" << endl;

but it dosn't because average < 77 does not evaluate to true should be average <= 77

or better yet cover the full range of grades else if ((average >= 70) && (average < 80) && (perfectattendance==1))

side note microsoft visual 2010 is out of date. You should upgrade to 2012.
Last edited on
thank you so much guys!!! definitely helped me out a lot
Just wanted to know if you wanted the program to evaluate perfect attendance? Because it is a bool that has been initialized with a 1 value it will always give perfect attendance for this program.
Topic archived. No new replies allowed.