If else statements (multiple cond.)

Hello,

I'm trying to build a program that tells you what letter grade you received based on the average of three different grades. You tell it was score you got in each class and it calcs. avg. for you. For some reason I can only get it to tell me I got an A or B. When I try entering for a D, D, or F avg. It doesn't work.

Lines 62-81

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	//Variable Declaration
	//int age = int();
	//double rate = double();
	int id;
	char gender = char();
	bool flag = bool();
	//double grade = grade();
	double sum = double();
	double avg = double();
	string fname = string();
	string lname = string();
	double egrade;
	double mgrade;
	double hgrade;
	//int A = ( > 90 )
	//int B = ( >= 80 )
	//int C = ( >= 70 )
	//int D = ( >= 60 )
	//int F = ( <60 )


	//Header
	cout << "Student Grading System (SGS) \t\t\tA = Greater than or equal to 90" << endl;
	cout << "Your College \t\t\tB = Less than 90 but greater than or equal to 80" << endl;
	cout << "Author: Seth Frias \t\t\tC = Less than 80 but greater than or equal to 70" << endl;
	cout << "Date Created: 2/20/18 \t\t\tD = Less than 70 but greater than or equal to 60" << endl;
	cout << "--------------------- \t\t\tF = Less than 60" << endl;

	//Input
	cout << "Please enter your first name: " << endl;
	cin >> fname;
	cout << "Please enter your last name: " << endl;
	cin >> lname;
	cout << "Please enter your ID: " << endl;
	cin >> id;
	cout << "Please enter your English class score: " << endl;
	cin >> egrade;
	cout << "Please enter your Math class score: " << endl;
	cin >> mgrade;
	cout << "Please enter your History class score: " << endl;
	cin >> hgrade;
	cout << "---------------------" << endl;


	//Processing
	sum = (egrade + mgrade + hgrade);
	avg = sum / 3;
	
	//Output
	cout << "First name: " << fname << endl;
	cout << "Last name: " << lname << endl;
	cout << "ID: " << id << endl;
	cout << "Total: " << sum << endl;
	cout << "Average: " << avg << endl;
	if (avg >= 90)
	{
		cout << "Grade: A " << endl;
	}
	else if (avg < 90)
	{
		cout << "Grade: B" << endl;
	}	
	else if (avg < 80 && avg > 69)
	{
		cout << "Grade: C" << endl;
	}
	else if (avg < 70 && avg > 59)
	{
		cout << "Grade: D" << endl;
	}
	else
	{
		cout << "Grade: F" << endl;
	}
	

	system("pause");
	return 0;
}
Last edited on
1
2
3
4
5
if (avg >= 90) cout << "Grade: A \n"; // >= 90
else if( avg >= 80 ) cout << "Grade: B\n"; // >= 80, < 90
else if( avg >= 70 ) cout << "Grade: C\n"; // >= 70, < 80
else if( avg >= 60 ) cout << "Grade: D\n"; // >= 60, < 70
else cout << "Grade: F\n"; // < 60 
Topic archived. No new replies allowed.