# Calculate grade average with weights

`This C++ program will calculate the average of 4 grades by using weight calculation. It will then display the average and give the user a chance to review the grades.`
1. #include <cstdlib>
2. #include <iostream>
3. using namespace std;
4. bool isitvalid(double[]);
5. bool printarray(double[], int);
6. int main()
7. {
8.  // To hold the weights and the grades
9.  double weights[4];
11.  // To hold the averages
14.  int numOfStudents = 0;
15.  char respChar = ‘N’;
17.  bool anotherStudent = false;
18.  // Do until the user decides not to enter anymore students
19.  do
20.  {
21.  // Loop for the user to enter the weight
22.  for(int i = 0; i < 4; i++)
23.  {
24.  cout << “Please enter weight for grade (e.g. 0.3) #” << i + 1 << “: “;
25.  cin >> weights[i];
26.  }
27.  // Loop for the user to enter the grades (until all are valid)
28.  do
29.  {
30.  for(int i = 0; i < 4; i++)
31.  {
32.  cout << “Please enter grade #” << i + 1 << “: “;
34.  }
35.  }
37.  // Loop to calculate the average
38.  for(int i = 0; i < 4; i++)
39.  {
41.  }
42.  // Show the final grade
43.  cout << “The final grade is: ” << avrGrade << “\n“;
44.  // If the user wants to review the grades, call the printarray() function
45.  cout << “Enter the number of grades you want to review (0 to continue): “;
48.  {
50.  }
51.  cout << “Would you like to enter another student? Type Y for Yes anything else for No: “;
52.  cin >> respChar;
53.  // Holds the average class grade
55.         numOfStudents++;
56.  }
57.  while(respChar == ‘Y’);
58.  // When the loops and conditions are all complete show the class average
59.  cout << “\nThe class average is ” << avrClassGrade / numOfStudents << “\n“;
60.  system(“PAUSE”);
61.  return 0;
62. }
64. {
65. // Will be set to true if a bad grade is found
67. for(int i = 0; i < 4; i++)
68. {
70. {
72. }
73. }
75. {
76. return false;
77. }
78. else
79. {
80. return true;
81. }
82. }