Basic Functions And Subroutines (C++)


SUBMITTED BY: yppah

DATE: Jan. 24, 2016, 5:33 a.m.

FORMAT: Text only

SIZE: 496 Bytes

HITS: 4771

  1. #include
  2. using namespace std;
  3. double harmean(int x,int y);
  4. int main()
  5. {
  6. int a, b;
  7. cout<<"Please, enter two integers: ";
  8. while (!(cin>>a)||!(cin>>b)||a==0||b==0)
  9. {
  10. cin.clear();
  11. while(cin.get()!='\n')
  12. continue;
  13. cout<<"\nPlease, enter two integers: ";
  14. }
  15. cout<<"\nThe harmonic mean of "<<a<<" and "<<b<<" = "<<harmean(a,b);
  16. cout<<"\n\n";
  17. return 0;
  18. }
  19. double harmean(int x, int y)
  20. {
  21. double hm=0.0;
  22. hm=2.0*x*y/(x+y);
  23. return hm;
  24. }

comments powered by Disqus