finding the average

Nov 17, 2014 at 3:09am
Program instructions:
Write a program that would allow a user to enter student names and Final grades (e.g. A,B,C,D,F) from their courses. You do not know how many students need to be entered. You also do not know how many courses each of the students completed. Design your program to calculate the Grade Point Average (GPA) for each student based on each of their final grades. The program should output the Student name along with the GPA.


I have written a program which allows me to have a user input grades and have the program average their total grade. However, I need to make it so that the user is able to input a letter grade (a,b,c,d) and have the program convert each letter to their corresponding values (a=4,b=3,c=2,d=1) and then average their grade according to THOSE numbers so as to accurately calculate their GPA.

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

int main() {
	string nameStudent;
	double sumGrade = 0;
	double grade;
    int numGrade;

	cout << "Enter name of student" << endl;
	cin >> nameStudent;

	cout << "Please enter the number of grades" << endl;
	cin >> numGrade;

	for (int count = 1; count <= numGrade; count++)
	{
		cout << "PLease input a grade ";
		cin >> grade;
		sumGrade += grade;
	}

	double average = sumGrade/numGrade;


	cout << nameStudent << " 's average grade is " << average;


	return 0;

}


What do I need to add to this code to make these changes? Any help would be greatly appreciated as this assignment is due in 90 minutes! Thanks in advance and hopefully someone reads this before then. ANY HELP WOULD BE VERY MUCH APPRECIATED!
Last edited on Nov 17, 2014 at 3:13am
Nov 17, 2014 at 3:24am
Example for input and expected output

Input:
Sally: A,D,B,C

Expected output
GPA for Sally is: 2.5


Last edited on Nov 17, 2014 at 3:26am
Nov 20, 2014 at 4:53am
Anybody? Still trying to figure this out.
Nov 20, 2014 at 5:15am
Have the user input a char for a letter grade (A, B, C, D, F) and then use a switch statement to associate the letter grade with an actual grade point.
Nov 22, 2014 at 12:18am
OK i finally figured it out but now I cant get it to "float" the gpa so i only get whole numbers when i should be gettting fractions. For instance a+b+c+d should average out to 2.5 but i get "2"
Nov 22, 2014 at 12:19am
Here's my revised code. Like I said everything is fine except the fact that I can't get non-whole numbers.

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

int main() {
	char studentName[100];
	double sumGrade;
    double numGrade;
    char grade;
    double gpa;

    //reset sums to 0
      sumGrade = 0.0;
      cout << "Enter Student Name" << endl;
      cin >> studentName;

    	cout << "Please enter the number of grades" << endl;
    	cin >> numGrade;


    	for (double count = 1; count <= numGrade; count++)
    	        			{
    	  cout << "PLease input a grade ";
    	  cin >> grade;
    	  sumGrade += grade;
    	        			}




    switch (grade)
    		{
    		case 'a':
    			gpa = 4.0;
    			break;
    		case 'b':
    			gpa=3.0;
    			break;
    		case 'c':
    			gpa=2.0;
    			break;
    		case 'd':
    			gpa=1.0;
    		    break;
    		case 'f':
    			gpa=0.0;
    			break;
    		default :
    			cout << "Invalid grade" << endl;
    		}

    cout << studentName << " 's average grade is " << gpa;


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