Grade averaging calculator

I am writing this program for a project and I can not get this to run at all. It executes the first cout command and then the command prompt disappears. If any of you can assist me it will be a big help. There seems to be no build errors by the way.

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 <iomanip>
using namespace std;


int statements(char grade)

{
	if ((grade == 'a') || (grade == 'A')) 
	{ 
		grade = 4;
	}
	
	else if ((grade == 'b') || (grade == 'B')) 
	{ 
		grade = 3; 
	}
	
	else if ((grade == 'c') || (grade == 'C')) 
	{ 
		grade = 2;
	}

	else if ((grade == 'd') || (grade == 'D')) 
	{ 
		grade = 1;
	}

	else if ((grade == 'f') || (grade == 'F')) 
	{ 
		grade = 0;
	}

	else
	{
		return 0;
	}
}

int main()
{
	char grade_1, grade_2;
	int credit_1, credit_2, gradeval_1, gradeval_2;
	double GPA;
	cout << "Enter course 1 letter grade:  ";
	cin >> grade_1;
	gradeval_1 = statements(grade_1);
	if (gradeval_1 == -1)
	{
		cout << "Nonvalid letter grade";
	}
	else if (grade_1 ==5)
	{
		cout << "Nonvalid letter grade";
	}

	return 0;

	{
		cout << "Enter Course 1 credit hours: ";
		cin >> credit_1;
		cout << "Enter Course 2 letter grade: ";
		cin >> grade_2;
		gradeval_2 = statements(grade_2);
		if (gradeval_2 == -1)
		{
			cout << "Nonvalid letter grade";
		}
		else if (grade_2 == 5)
		{
			cout << "Nonvalid letter grade";
		}
		cout << "Enter Course 2 credit hours:  ";
		cin >> credit_2;
		GPA = (gradeval_1*credit_1 + gradeval_1*credit_2) / double(credit_1 + credit_2);
		
		if (GPA <= 2.75)
		{
			cout << "warning do better young lad  \n";
		}
		else if (GPA>=3.5)
		{
			cout << "CONGRATULATIONS YOUNG PADAWAN!";
		}
		return 0;
	}
Last edited on
if statements() all of those grade = n; lines need to be return statements like the else is.

@line 49 - this can never happen, -1 is never returned from statements()

@line 57, this is exiting the program before GPA is calculated.
If you are using microsoft visual studio c++ then use system("pause") instead of return 0

and you also need to return grade in

int statements(char grade);

and why you are using -1
Last edited on
Topic archived. No new replies allowed.