# function problem

Printable View

• 09-15-2006
plain
function problem
I am trying to compile this in DevC++ but I keep getting hung up with the error..
" 'h' cannot be used as a function." Is there something I`m missing? I`ve been assigning different letters to equations all night and this is the first problem I`ve had. Thanks for the help. Plain

Code:

```//Here's a piece on horizontal cylinders, circular and elliptical, //that may be //what you want. //Consider a circle of radius a (the end of the tank) //and imagine that the liquid //has reached //height h, measured from the lowest point on the circle.  //Note that  0 <= h <= 2a.  The area A //of the segment of the circle covered by the liquid is //A = pi*a^2/2 - a^2*arcsin(1-h/a) - (a-h)*sqrt(h(2a-h)). //Note: your calculator should be set in radians. //Now multiply A * L. //This program calculates the partial volume of a horizontal cylinder. //a = r, h = measured liquid // #include <cstdlib> #include <iostream> #include <math.h> using namespace std; int main() { double fillvol; double pi = 3.141592; double r; double h; double L; cout << "Enter the radius of the circular cylinder in "; cout << "decimal feet: "; cin >> r; cout << "The circular area of the cylinder is: "; cout << ((r * r) * pi) << "feet.\n";   cout << "Enter the height of the liquid in decimal feet: ";   cin >> h;   cout << "The liquid height is " << h << "feet.";       cout << "Now enter the length of the cylinder: ";       cin >> L;         cout << "The volume of liquid in the cylinder is: ";         cout << L * ((pi * ((r*r)/2)) - ((r*r)*(asin(1-(h/r))) - (r-h)*sqrt(h(2r-h))));         cout << "cubic feet"; system("PAUSE"); return 0; }```
• 09-15-2006
dwks
Code:

`sqrt(h(2r-h))`
->
Code:

`sqrt(h * (2r-h))`
You can't just stick two numbers/variables together in C++ and hope they get multiplied together; you need to use the multiplication operator *.
• 09-15-2006
Desolation
If I recall, there is a define for pi in math.h and cmath (which you should use instead o f math.h). It's "PI".
• 09-15-2006
Dave_Sinkula
Quote:

Originally Posted by Desolation
If I recall, there is a define for pi in math.h and cmath (which you should use instead o f math.h). It's "PI".

Or not.
• 09-15-2006
plain
Of course! Thank you DWKS I should have known better.

The pi thing.....I`m lost can you enlighten me?
• 09-16-2006
jarro_2783
it's M_PI
• 09-16-2006
risby
Quote:

Originally Posted by jarro_2783
it's M_PI

Or, as Homer would say, "Mmmmmmmmmmm, pi".
• 09-16-2006
Dave_Sinkula
Quote:

Originally Posted by jarro_2783
it's M_PI

Or not.

There isn't a standard symbol for pi.
• 09-16-2006
dwks
Many compilers have M_PI, but some do not. It's best to define it yourself as you have done.

You got the value wrong, however. :)
Code:

`double pi = 3.141592;`
pi is 3.14159265358979... so it isn't 3.141592, it's 3.141593.