fork download
  1. #include <study.hpp>
  2.  
  3. // Lesson: Find average of several doubles
  4. // Every exercise will consist of a number of non-negative doubles. After all
  5. // are read, the stream will become invalid.
  6.  
  7. // Syntax: Check stream state to see if there is more data for this exercise.
  8. // MAIN is called externally, once for every exercise.
  9.  
  10. int MAIN()
  11. {
  12. double d;
  13. double total = 0.0;
  14. int count = 0;
  15. while (study::cin >> d) // Will be true until all data is read.
  16. {
  17. total += d;
  18. ++count;
  19. }
  20. study::cout << (total/count) << study::endl; // Submits the answer.
  21. return 0;
  22. }
  23.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty