Advertisement
BlackWolfy

Program for calculating the average of students and displaying failed classes

Feb 5th, 2023 (edited)
1,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int grades[50][10], s, c;
  6.     cout << "Number of students: "<<endl;
  7.     cin >> s;
  8.     cout << "Number of classes the students took: "<<endl;
  9.     cin >> c;
  10.     for (int i = 0; i < s;i++) { //loop for entering grades
  11.         cout << "Enter the grades for student "<<i+1<<": "<<endl;
  12.         for (int j = 0; j < c;j++) {
  13.             cin >> grades[i][j];
  14.         }
  15.     }
  16.     for (int i = 0; i < s;i++) { //loop for displaying grades
  17.         float sum = 0.0;
  18.         int counter=0;
  19.         for (int j = 0; j < c;j++) {
  20.             if (grades[i][j] == 2) {
  21.                 counter++;
  22.             }
  23.             else {
  24.                 sum = sum + grades[i][j];
  25.             }
  26.         }
  27.         if (counter>0) {
  28.             cout << "Student "<<i+1<<" has failled "<<counter<<" classes!"<<endl;
  29.         }
  30.         else {
  31.             cout << "Student " << i + 1 <<" has an average of "<<sum/c<<"." << endl;
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement