fork download
  1. #include <algorithm>
  2. #include <string>
  3. #include <map>
  4. #include <iostream>
  5.  
  6. std::map<std::string, float> marks ={{"Joe", 90}, {"Jim", 85}};
  7.  
  8. float getAverageMark()
  9. {
  10. if ( marks.empty())
  11. return 0;
  12. return std::accumulate(marks.begin(), marks.end(), 0.0f, [&](float f, auto&pr)
  13. { return f + pr.second;}) / marks.size();
  14. }
  15.  
  16. int main()
  17. {
  18. std::cout << getAverageMark();
  19. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
87.5