Grading Scale

Okay so I am trying to get this code to work but I am stuck. I have to accept the numerical grade and determine the letter grade that the user will receive. I have to use a grading table to determine the letter grade based on the numerical grade. The Letter Grade table is
A 90-100
B 80-89
C 70-79
D 60-69
F 59 and below

Here is the code

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
//preprocessor directives
#include <iostream>
#include <string>

//namespace statement
using namespace std;

//function prototypes 
void getData (string& course, string& first, string& last, int& grade);
void testGrade (int grade, bool& passFail);
void determineGrade (int grade, string& letterGrade);
void printResults (bool pressFail, string first, string last, string course, string letterGrade);

//main function
int main (){
	//declare a variable called course that can hold words
	string course;
	//declare a variable called first that can hold words
	string first;
	//declare a variable called last that can hold words
	string last;
	//declare a variabele called letterGrade that can hold words
	string letterGrade;
	//declare a variable called int that can whold numbers
	int grade;
	//declare a variable called passFail that can hold bool
	bool passFail;
	//function calls
	getData (course, first, last, grade);
	testGrade (grade, passFail);
	//print "Press any key to continue..." and wait for key press
	system ("pause");
	//end main function
	return 0;
}
        void getData (string& course, string& first, string& last, int& grade){
		//prompt the user to "Enter your course:"
		cout << "Enter your course:" << endl;
		//wait for input and store in course
		cin >> course;
		//prompt the user to "Enter your First Name:"
		cout << "Enter your First Name:" << endl;
		//wait for input and store in first
		cin >> first;
		//prompt the user to "Enter your Last Name:"
		cout << "Enter your Last Name:" << endl;
		//wait for input and store in last
		cin >> last;
		//prompt the user to enter your grade
		cout << "Enter your grade:" << endl;
		//wait for input and store in grade
		cin >> grade;
	}
        void testGrade (int grade, bool& passFail){
			//test to see if grade is higher than 65
			if (grade > 65){
				//if true than they pass and pring "Pass!"
				passFail = true;
				cout << "Pass!";
			}else if (grade < 65){
				passFail = false;
				cout << "Fail!";
			}
		}
 
		  void determineGrade (int grade, string& letterGrade){
			  //check to see if grade is 90 or above
			  if ((grade > 90) && (grade <= 100)){

			  }else if ((grade > 80) && (grade <= 89)){ 
				  letterGrade = B;


As you can see, I am currently stuck on the determineGrade one
Last edited on
Ok, think. In main, you use a keyword named return. And the term int on the function. So, you can return something from a function. Oh, use the function to return the number!
Ok, now you only must check what's the number. Ok, we'll use a map. Map is just what you think, a map. You enter the coordinate and it will correspond to the inputed number for this. Read about map in the internet.
So, create a map. Let's suppose:
1
2
3
4
#include <map>
std::map<std::string, int> grade_number;
grade_number["A"] = 100;
...

And then
1
2
3
4
int get_grade(std::string &str)
{
    return grade_number[str];
}

1
2
3
4
main() 
{
...
    if(get_grade(inputed_string) == 100) { ... //A 
Last edited on
Topic archived. No new replies allowed.