Thread: function problem

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    23

    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;
    }

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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 *.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    903
    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".

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    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.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    23
    Of course! Thank you DWKS I should have known better.

    The pi thing.....I`m lost can you enlighten me?

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    17
    it's M_PI

  7. #7
    Registered Luser risby's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Quote Originally Posted by jarro_2783
    it's M_PI
    Or, as Homer would say, "Mmmmmmmmmmm, pi".
    ===
    Don't grumble about what you can't have;
    be grateful you don't get what you deserve.

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by jarro_2783
    it's M_PI
    Or not.

    There isn't a standard symbol for pi.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-29-2008, 06:33 AM
  2. wxWidgets link problem
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 02:36 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM