fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <sstream>
  4. #include <string>
  5.  
  6. int main()
  7. {
  8. std::cout << std::fixed << std::setprecision(2);
  9. std::string line;
  10. std::getline(std::cin, line);
  11. std::istringstream input(line);
  12. double sum = 0;
  13. int num = 0;
  14. double n;
  15. while(input >> n) {
  16. sum += n;
  17. ++num;
  18. }
  19. double avg = sum/num;
  20. std::cout << avg << '\n';
  21. }
Success #stdin #stdout 0s 3432KB
stdin
2 4.5 7
3 //should not be included
stdout
4.50