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?
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace 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 = newdouble[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 = newdouble[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 = newdouble[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';
}
elseif (FINAL_avr >= 80)
{
LETTER_grade = 'B';
}
elseif (FINAL_avr >= 70)
{
LETTER_grade = 'C';
}
elseif (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;
}