// program to calculate the harmonic mean of values input #include int main() { try{ int countno(0); double total(0.0); double h(0.0); double result(0.0); while(true) { double value(0); std::cout << "Next value please:(1000 to end input) "; std::cin >> value; if(not std::cin) throw std::exception(); if(value > 999) break; result = (1/value); // the reciprocal of this number is total += result; // add this to total reciprocals std::cout << "the reciprocal of 1/" << value << " is " << result << '\n'; std::cout << "total is " << total << '\n'; ++countno; } h = countno/total; //harmonic mean std::cout << "\nYou input " << countno << " values" << '\n'; std::cout << "The total reciprocals is " << total << '\n'; std::cout << "The Harmonic Mean of these values is " << h; } catch(...) { std::cerr << "***An exception was thrown.***\n"; } }