# harmonic mean

• 03-19-2002
curlious
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
• 03-19-2002
Green
Semicolon's after declaration of structs...

// structure template
struct par
{
double a;
double b;
};
• 03-19-2002
Denethor2000
// 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);
}
• 03-19-2002
Denethor2000
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);
}
• 03-19-2002
biosx
Denethor2000, you could have just edited the post then instead of posting again. :)