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, followed
  5. // by a -1.0. Once this is read, the average of the doubles should be printed
  6. // (the -1.0 should not be included in the count).
  7.  
  8. // Syntax: Check stream state for end of lesson, check values for end of exercise.
  9. int main()
  10. {
  11. while(study::cin) // Will be false after the last exercise
  12. {
  13. double d;
  14. double total = 0.0;
  15. int count = 0;
  16. while (study::cin >> d && d != -1.0) // study::cin >> d will always be true.
  17. {
  18. total += d;
  19. ++count;
  20. }
  21. study::cout << (total/count) << study::endl; // Submits the answer.
  22. }
  23. }
  24.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty