Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- int main()
- {
- // 1 = freshman
- // 2 = sophomores
- // 3 = juniors
- // 4 = seniors
- int cls = 0, cont = 0;
- vector< int > totalContribution(5, 0);
- map< int, string > m;
- m[1] = "freshman";
- m[2] = "sophomores";
- m[3] = "juniors";
- m[4] = "seniors";
- while(1) {
- cout << "Enter class: ";
- cin >> cls;
- if(cls < 1 || cls > 4) {
- cout << "You have entered wrong class\n";
- break;
- }
- cout << "Enter contributed amount: ";
- cin >> cont;
- totalContribution[cls] += cont;
- }
- int mx = 0;
- for(int i=1; i<=4; i++) {
- mx = max(mx, totalContribution[i]);
- cout << "Total contribution of class " << i << "(" << m[i] << ")" << ": " << totalContribution[i] << "\n";
- }
- cout << "Class(es) that contributed the most: ";
- for(int i=1; i<=4; i++) {
- if(mx==totalContribution[i]) cout << i << " ";
- }
- cout << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment