my code is perfect i just have a problem Using a switch to determine the letter grade and grade points

this is what i have so far


#include <iostream>
using namespace std;

int main()
{
// scores required for each letter grade.
const int A_SCORE = 90,
B_SCORE = 80,
C_SCORE = 70,
D_SCORE = 60,
F_SCORE = 0;

int numericGrade; // Holds a numeric test score
char letterGrade; // Holds a letter grade
int gradePoints; // Holds number of points earned

// Get the numeric score
cout << "Please type in your grade: \n";
cin >> numericGrade;

// Determine the letter grade. What grade will be assigned?
if (numericGrade >= A_SCORE)
{
letterGrade = 'A';
gradePoints = 4;
}
else if (numericGrade >= B_SCORE)
{
letterGrade = 'B';
gradePoints = 3;
}
else if (numericGrade >= C_SCORE)
{
letterGrade = 'C';
gradePoints = 2;
}
else if (numericGrade >= D_SCORE)
{
letterGrade = 'D';
gradePoints = 1;
}
else if (numericGrade >= F_SCORE)
{
letterGrade = 'F';
gradePoints = 0;
}

// Display the letter grade and points earned
cout << "\tYou made a " << letterGrade << " in the class and earned " << gradePoints << " points.\n";
system("pause");
return 0;
}
Here a example:

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
/*GabrielValedon2012*/
/*Switch & Case Example*/
#include <iostream>
using namespace std; //<-- this line avoid you to put std::cout, etc.

//Program will display your grade.
int main()
{
	cout << "Grade Calculator" << endl;
	cout << "----------------" << endl;

	int grade1;
	int grade2;
	int grade3;
	int grade4;
	int avg;

	cout << "Enter Grade 1: ";
	cin >> grade1;

	cout << "Enter Grade 2: ";
	cin >> grade2;

	cout << "Enter Grade 3: ";
	cin >> grade3;

	cout << "Enter Grade 4: ";
	cin >> grade4;

	avg = (grade1 + grade2 + grade3 + grade4)/4;

	if(avg >= 90)
	{
		cout << "Your Average Is: " << avg << " A" << endl;
	}
	else if(avg < 90 && avg >= 80)
	{
		cout << "Your Average Is: " << avg << " B" << endl;
	}
	else if(avg < 80 && avg >= 70)
	{
		cout << "Your Average Is: " << avg << " C" << endl;
	}
	else if(avg < 70 && avg >= 60)
	{
		cout << "Your Average Is: " << avg << " D" << endl;
	}
	else if( avg < 60 && avg >= 50)
	{
		cout << "Your Average Is: " << avg << "F" << endl;
	}
	else
	{
		cout << "Your Grade Is Under 50..." << endl;
	}

	return 0;
}
Here a example:

Noticeably omitting the one thing the OP asked for: a switch statement. (Also, redundant conditions -- avg must be less than 90 if line 36 is evaluated so there's no reason to check for it.)

To the OP: Switches don't work for ranges unless you can map the ranges to specific integral values. Something like the following for your use case:

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
#include <iostream>
using namespace std;

int main()
{
    // scores required for each letter grade.
    const int A_SCORE = 90,
              B_SCORE = 80,
              C_SCORE = 70,
              D_SCORE = 60,
              F_SCORE = 0;

    int numericGrade; // Holds a numeric test score
    char letterGrade; // Holds a letter grade
    int gradePoints; // Holds number of points earned

    cout << "Please type in your grade: \n";
    cin >> numericGrade;

    switch (numericGrade / 10) {
        case 10:    // fall through to 9.
        case 9:  letterGrade = 'A';  gradePoints = 4; break;
        case 8:  letterGrade = 'B';  gradePoints = 3; break;
        case 7:  letterGrade = 'C';  gradePoints = 2; break;
        case 6:  letterGrade = 'D';  gradePoints = 1; break;
        default: letterGrade = 'F';  gradePoints = 0; break;
    }

    // Display the letter grade and points earned
    cout << "\tYou made a " << letterGrade << " in the class and earned " << gradePoints << " points.\n";
}

Thank you guys so much for your help!!
Topic archived. No new replies allowed.