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. // check the lesson to check if there are more exercises.
  9.  
  10. extern study::LessonInterface lesson;
  11.  
  12. int main()
  13. {
  14. while(lesson) // Will be false after the last exercise
  15. {
  16. double d;
  17. double total = 0.0;
  18. int count = 0;
  19. while (study::cin >> d) // Will be true until all data is read.
  20. {
  21. total += d;
  22. ++count;
  23. }
  24. study::cout << (total/count) << study::endl; // Submits the answer.
  25. }
  26. }
  27.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty