fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. int main()
  6. {
  7. std::vector<unsigned> grades;
  8. unsigned grade;
  9. std::cin >> grade;
  10. while (grade != 0) {
  11. grades.push_back(grade);
  12. std::cin >> grade;
  13. }
  14. std::cout << "You have entered " << grades.size() << " elements" << std::endl;
  15. std::cout << "Your GPA is " << (std::accumulate(grades.begin(), grades.end(), 0u) / grades.size()) << std::endl;
  16. }
Success #stdin #stdout 0s 3432KB
stdin
50 50 100 100 0
stdout
You have entered 4 elements
Your GPA is 75