我正在为一个班级做一个项目,我在输出几何平均值时遇到了麻烦,它总是为 1,我确信这是不对的。
这是我的代码:
#include<iostream>
#include<math.h>
using namespace std;
int main(int argc, char**argv)
{
float i, j, k;
float a, h, g;
cout<<"Enter 3 floating point numbers"<<endl;
cin>>i>>j>>k;
while(i>0 && j>0 && k>0 )
{
a = (i+j+k)/3;
h = 3/((1/i) + (1/j) + (1/k));
g = pow((i*j*k),(1/3));
cout<<"Arithmetic: "<<a<<endl;
cout<<"Harmonic: "<<h<<endl;
cout<<"Geometric: "<<g<<endl;
cout<<"Enter 3 floating point numbers"<<endl;
cin>>i>>j>>k;
}
return(0);
}