Advertisement
andruhovski

SP-0301a (exception)

Feb 9th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. double hmean (double a, double b);
  6. int main ()
  7. {
  8.     double x, y, z;
  9.     cout << "Enter two numbers:";
  10.     while (cin >> x >> y)
  11.     {
  12.         z = hmean (x, y);
  13.         cout << "Harmonic mean of " << x << " and " << y << " is " << z << "\n";
  14.         cout << "Enter next set of numbers <q to quit>:";
  15.     }
  16.         cout << "Bye!\n";
  17.         return 0;
  18. }
  19. double hmean ( double a, double b)
  20. {
  21.     if (a == -b)
  22.     {
  23.         cout << "untenable arguments to hmean ()\n";
  24.         abort ();
  25.     }
  26.     return 2.0 * a * b / (a + b);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement