CGPA

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<iostream>
using namespace std;

void Introduction(string, long);
float CalcGPA(float, float);
float totalGPA(float[], int);
float CalTotCredit(float[], int);

int main()
{
	char choice;
	float totalcredit=0, G=0, TC=0;	
	string name;
	long MatrixNo;
	int j, noSemester;
	float GPA[j], totcredit[j], TGPA=0, TotalCredit=0,CGPA=0, Tcredit=0, totalCredit;
	cout<<"Do you want to calculate CGPA? Yes='Y'/No='N'";
	cin>>choice;
	if(choice=='Y'||choice=='y')
	{
		cout<<"How many semesters did student take for his/her course?";
		cin>>noSemester;
		for(j=0; j<=noSemester; j++)
		{
			Introduction(name, MatrixNo);
			cout<<"Semester: "<<j+1;	
			CalcGPA(GPA, totalCredit);
			GPA[j]=G;
			totcredit[j]=TC;
		}
		totalGPA(GPA, noSemester);
		TGPA+=totalGPA(GPA, noSemester);
		Tcredit+=CalTotCredit(TC[], noSemester);
		CGPA=TGPA/TC;
		cout<<name<<", "<<MatrixNo<<" have CGPA of "<<CGPA;
		cout<<"Do you want to calculate CGPA? Yes='Y'/No='N'";
		cin>>choice;
	}
	else
		if(choice=='N'||choice=='n')
			cout<<"Thank you for using this program. Have a nice day!!!"<<endl;
		else
		{
			cout<<"Sorry wrong input!!! Please try again...";
			cout<<"Do you want to calculate CGPA? Yes='Y'/No='N'";
			cin>>choice;
		}
	system("PAUSE");
	return 0;
}

void Introduction(string name, long MatrixNo)
{
	cout<<"Student's name: ";
	cin>>name;
	cout<<"Enter "<<name<< "matrix number: ";
	cin>>MatrixNo;
}

float CalcGPA(float &GPA,float &totalCredit)
{
	int j=0, NoOfSubject=0;
	float credit, point, total;
	cout<<"Number: "<<j+1;
	cout<<"How many subjects did you take in a semester?";
	cin>>NoOfSubject;
	for(int i=0; i<NoOfSubject; i++)
	{
		cout<<"Credit: ";
		cin>>credit;
		cout<<"Point: ";
		cin>>point;
		totalCredit+=credit;
		total=credit*point;
	}
	GPA=total/totalCredit;
	
}

float totalGPA(float GPA[], int noSemester)
{
	float Total_GPA=0;
	int i=0;
	while(i<noSemester)
	{
		Total_GPA+=GPA[i];
		i+=1;
	}
	return Total_GPA;	
}

float CalTotCredit(float tc[],int ts)
{
	float Tcredit=0, CGPA=0;
	int i=0;
	while(i<ts)
	{
		Tcredit+=tc[i];
	}
	return Tcredit;
}



I couldnt run it. I am very new to this and I need to send it ASAP. Can you guys debug it for me and tell me where did I go wrong as I am running out of ideas.
Last edited on
I couldnt run it.

What do you mean? Does it fail to compile? If so, tell us what the compiler errors are.

Does it compile, but crash when running?

Does it run without crashing, but exhibit some unexpected behaviour?

We're not mind-readers! Give us information about your problem, so that we can help you.

EDIT: From glancing at your Introduction function, I can see you're passing in arguments by value, but then changing those values inside the function. If you want those new values to be visible in the calling code, you need to pass those arguments by reference, just as you do elsewhere in your code.

Also, at line 16, your array definitions aren't legal. You can't declare an array with a variable length - that's illegal. You need to specify a size that's known at compile-time.

(Even if you could do that, your declaration would make no sense, because you would be using j without ever having given it a value.)
Last edited on
Topic archived. No new replies allowed.