harmonic mean

This is a discussion on harmonic mean within the C++ Programming forums, part of the General Programming Boards category; Coule someone help me debug this program. I don't know whats wrong with it. // harmonic mean pg289 c++ primer ...

  1. #1
    curlious
    Guest

    harmonic mean

    Coule someone help me debug this program. I don't know whats wrong with it.

    // harmonic mean pg289 c++ primer plus

    #include <iostream>
    using namespace std;

    // structure template
    struct par
    {
    double a;
    double b;
    }

    // prototypes
    double harmonic_mean(par ab);

    int main()
    {
    par xy;
    double hm;

    cout << "Enter a pair of numbers:";

    while ((cin >>xy.a>>xy.b))
    {
    hm=harmonic_mean(xy);
    cout << "The harmonic mean is:" << hm <<endl;
    cout << "Enter a pair of numbers:";
    }

    return 0;
    }

    double harmonic_mean(par ab)
    {
    return 2.0*ab.a*ab.b/(ab.a+ab.b);
    }


    ps i am using borelands compiler

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    3
    Semicolon's after declaration of structs...

    // structure template
    struct par
    {
    double a;
    double b;
    };

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    // harmonic mean pg289 c++ primer plus

    #include <iostream>
    using namespace std;

    // structure template
    struct par
    {
    double a;
    double b;
    }

    // prototypes
    double harmonic_mean(par ab);

    int main()
    {
    par xy;
    double hm;

    cout << "Enter a pair of numbers:";
    cin<<hm;

    while ((hm>>xy.a>>xy.b))
    {
    hm=harmonic_mean(xy);
    cout << "The harmonic mean is:" << hm <<endl;
    cout << "Enter a pair of numbers:";
    }

    return 0;
    }

    double harmonic_mean(par ab)
    {
    return 2.0*ab.a*ab.b/(ab.a+ab.b);
    }

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    sry, i messed up last time -
    // harmonic mean pg289 c++ primer plus

    #include <iostream>
    using namespace std;

    // structure template
    struct par
    {
    double a;
    double b;
    }

    // prototypes
    double harmonic_mean(par ab);

    int main()
    {
    par xy;
    double hm;

    cout << "Enter a pair of numbers:";
    cin>>hm;

    while ((hm>>xy.a>>xy.b))
    {
    hm=harmonic_mean(xy);
    cout << "The harmonic mean is:" << hm <<endl;
    cout << "Enter a pair of numbers:";
    }

    return 0;
    }

    double harmonic_mean(par ab)
    {
    return 2.0*ab.a*ab.b/(ab.a+ab.b);
    }

  5. #5
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Denethor2000, you could have just edited the post then instead of posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Average, Geo and Harmonic mean calcl
    By beone2 in forum C Programming
    Replies: 4
    Last Post: 06-24-2009, 05:59 PM
  2. Recursion
    By arctic_blizzard in forum C Programming
    Replies: 9
    Last Post: 10-26-2008, 04:37 PM
  3. Program for average, geometric mean, harmonic mean
    By Northstar in forum C Programming
    Replies: 5
    Last Post: 11-07-2007, 10:33 AM
  4. Help with program harmonic series
    By ramayana in forum C Programming
    Replies: 4
    Last Post: 12-15-2005, 09:02 AM
  5. Darned Harmonic Mean!
    By Sennet in forum C++ Programming
    Replies: 2
    Last Post: 11-02-2005, 08:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21