HELP NEEDED with functions, CODE included

So I need to compartmentalize this code into different functions which will be called by the main. I have been having issues with calling the dynamic arrays into the functions I write, will someone kindly tell me where I'm wrong here?

PS. My skill is entry level
Thanks-Rob

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

/*void enterScores(double HW,double LAB,double EXAM)
{

}
	;

	*/
int main()
{
	// Variable HW_count represents the number of recorded homework scores.
	// Variable LAB_count represents the number of recorded lab scores.
	// Variable EXAM_count represents the number of recorded exam scores.
	int HW_count;
	int LAB_count;
	int EXAM_count;
	// Variable HW_per represents the weight of recorded homework scores.
	// Variable LAB_per represents the weight of recorded lab scores.
	// Variable EXAM_per represents the weight of recorded exam scores.
	double HW_per;
	double LAB_per;
	double EXAM_per;
	// Variable HW_scores is an dynamic array containing the actual values of the recorded homework scores.
	// Variable LAB_scores is an dynamic array containing the actual values of the recorded lab scores.
	// Variable EXAM_scores is a dynamic array containing the actual values of the recorded exam scores.
	double *HW_scores;
	double *LAB_scores;
	double *EXAM_scores;

	double HW_avr=0; //used for calculation
	double LAB_avr=0; //used for calculation
	double EXAM_avr=0;//used for calculation

	double HW_sum=0; //used for calculation
	double LAB_sum=0; //used for calculation
	double EXAM_sum=0;//used for calculation

	double HW_final=0; //used for calculation
	double LAB_final=0; //used for calculation
	double EXAM_final=0;//used for calculation

	double FINAL_avr;//Final number grade
	char LETTER_grade;//

	//the following is used to collect data from the end user
	cout <<"Enter the number of homework: \n";
	cin >> HW_count;
	cout <<"Enter the number of labs: \n";
	cin >> LAB_count;
	cout <<"Enter the number of exams: \n";
	cin >> EXAM_count;
		system ("CLS");
	
	cout <<"Enter the percent weight of homework: \n";
	cin >> HW_per;
	cout <<"Enter the percent weight of labs: \n";
	cin >> LAB_per;
	cout <<"Enter the percent weight of exams: \n";
	cin >> EXAM_per;
		system ("CLS");
	
	HW_scores = new double[HW_count];
	
	for (int x = 0; x < HW_count; x++)
	{
	cout << "Enter score for Homework " <<x+1<< "\n";
	cin >> HW_scores[x];
	}
		system ("CLS");	
	LAB_scores = new double[LAB_count];
	
	for (int x = 0; x < LAB_count; x++)
	{
	cout << "Enter score for lab " <<x+1<< "\n";
	cin >> LAB_scores[x];
	}
		system ("CLS");
	EXAM_scores = new double[EXAM_count];
	
	for (int x = 0; x < EXAM_count; x++)
	{
	cout << "Enter score for Exam " <<x+1<< "\n";
	cin >> EXAM_scores[x];
	}

	// this section calculates the average of the homework assignments, labs, and exams
		for (int x = 0; x < HW_count; x++)
	{
	HW_sum=HW_sum+HW_scores[x];
	}
		HW_avr =HW_sum/HW_count;

		for (int x = 0; x < LAB_count; x++)
	{
	LAB_sum=LAB_sum+LAB_scores[x];
	}
		LAB_avr =LAB_sum/LAB_count;

		for (int x = 0; x < EXAM_count; x++)
	{
	EXAM_sum =EXAM_sum+EXAM_scores[x];
	}
		EXAM_avr =EXAM_sum/EXAM_count;

	//this code calculates the weighted averages
			
	HW_final =(HW_avr*HW_per);
	LAB_final =(LAB_avr*LAB_per);
	EXAM_final =(EXAM_avr*EXAM_per);
	FINAL_avr=(HW_final+LAB_final+EXAM_final)/100;

	//this codes determines the letter grade
if (FINAL_avr >= 90)
{
    LETTER_grade = 'A';
}
else if (FINAL_avr >= 80)
{
    LETTER_grade = 'B';
}
else if (FINAL_avr >= 70)
{
    LETTER_grade = 'C';
}
else if (FINAL_avr >= 60)
{
    LETTER_grade = 'D';
}
else
{
    LETTER_grade = 'F';
} 

	
	//this code is the final output code

	system ("CLS");
	setprecision(4);

		cout << "\n Homework scores: \n\n";
	for (int x = 0; x < HW_count; x++)
	{
	cout << "Homework " <<x+1<< ": ";
	cout << HW_scores[x]<< " \n";
	}
	
		cout << "\n Lab scores: \n\n";
	for (int x = 0; x < LAB_count; x++)
	{
	cout << "Lab " <<x+1<< ": ";
	cout << LAB_scores[x]<< " \n";
	}
	
		cout << "\n Exam scores: \n\n";
	for (int x = 0; x < EXAM_count; x++)
	{
	cout << "Exam " <<x+1<< ": ";
	cout << EXAM_scores[x]<< " \n";
	}
	
	cout <<setprecision(4)<<"\n"<<"Homework average:" << HW_avr<< "\n";
	cout <<setprecision(4)<<"Lab average:" << LAB_avr<< "\n";
	cout <<setprecision(4)<<"Exam average:" << EXAM_avr<< "\n";
	cout <<setprecision(4)<<"Weighted average:"<< FINAL_avr<<"\n\n";
	cout <<setprecision(4)<<"Letter Grade:" <<LETTER_grade<<"\n\n\n";

	//this code deletes the dynamic arrays that were created during runtime to clear RAM
	delete HW_scores;
	delete LAB_scores;
	delete EXAM_scores;
	return 0;
}
Topic archived. No new replies allowed.