c++ - Finding Geometric Mean of user input -
I am working on a project for a class and I am having trouble producing the geometric mean, which is always Comes out to be 1 and I'm sure this is not right.
Here's my code:
# include & lt; Iostream & gt; # Include & lt; Math.h> using namespace std; Int main (int argc, char ** argv) {float i, j, k; Float a, h, g; Cout & lt; & Lt; "Enter floating point number 3" & lt; & Lt; Endl; CIN & gt; & Gt; I & gt; & Gt; J & gt; & Gt; K; While (i> 0 & amp; nbsp; J & gt; 0 and & amp; amp; amp; A & gt; 0) {a = (i + j + k) / 3; H = 3 / ((1 / i) + (1 / j) + (1 / k)); G = POW ((i * j * k), (1/3)); Cout & lt; & Lt; "Arithmetic:" & lt; & Lt; A & lt; & Lt; Endl; Cout & lt; & Lt; "Harmonic:" & lt; & Lt; H & lt; & Lt; Endl; Cout & lt; & Lt; "Geometry:" & lt; & Lt; G & lt; & Lt; Endl; Cout & lt; & Lt; "Enter floating point number 3" & lt; & Lt; Endl; CIN & gt; & Gt; I & gt; & Gt; J & gt; & Gt; K; } Return (0); }
1/3 one 0 < / Code>. You should write 1.0 / 3.0 (or 1. / 3 ) to get the floating point value.
Comments
Post a Comment