Asif_Anwar

Untitled

Nov 1st, 2021 (edited)
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <map>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     // 1 = freshman
  10.     // 2 = sophomores
  11.     // 3 = juniors
  12.     // 4 = seniors
  13.     int cls = 0, cont = 0;
  14.     vector< int > totalContribution(5, 0);
  15.     map< int, string > m;
  16.     m[1] = "freshman";
  17.     m[2] = "sophomores";
  18.     m[3] = "juniors";
  19.     m[4] = "seniors";
  20.    
  21.     while(1) {
  22.         cout << "Enter class: ";
  23.         cin >> cls;
  24.         if(cls < 1 || cls > 4) {
  25.             cout << "You have entered wrong class\n";
  26.             break;
  27.         }
  28.         cout << "Enter contributed amount: ";
  29.         cin >> cont;
  30.         totalContribution[cls] += cont;
  31.     }
  32.     int mx = 0;
  33.     for(int i=1; i<=4; i++) {
  34.         mx = max(mx, totalContribution[i]);
  35.         cout << "Total contribution of class " << i << "(" << m[i] << ")" << ": " << totalContribution[i] << "\n";
  36.     }
  37.     cout << "Class(es) that contributed the most: ";
  38.     for(int i=1; i<=4; i++) {
  39.         if(mx==totalContribution[i]) cout << i << " ";
  40.     }
  41.     cout << "\n";
  42.  
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment