//=============================================================================

#include <iostream>
#include <limits>
using namespace std;

//-----------------------------------------------------------------------------

int main()
{
   cout << "Aufg_08_03_Mittelwert_Varianz\n\n";

   int count = 0;
   double sum = 0.0;
   double squares = 0.0;

   for (double in;;)
   {
      cout << "Wert: ";
      cin >> in;
      if (cin.fail())
      {
         cout << "Fehlerhafte Eingabe - bitte wiederholen\n";
         cin.clear();
         cin.ignore(numeric_limits<streamsize>::max(), '\n');
         continue;
      }

      if (in == 0.0) break;

      ++count;
      sum += in;
      squares += in * in;
   }
   cout << '\n';

   if (count == 0)
   {
      cout << "Keine Werte\n- keine Berechnungen\n";
      return 0;
   }

   if (count == 1)
   {
      cout << "Nur ein Wert"
         << "\n- Mittelwert: " << (sum / count)
         << "\n- Varianz:    ---\n";
      return 0;
   }

    cout << "Werte: " << count
      << "\n- Mittelwert: " << (sum / count)
      << "\n- Varianz:    " << (squares / (count - 1)) << '\n';
}
