CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Posts
    15

    Pointer error in two lines of code

    Hi everyone,
    I'm typing up a program that allows the input of the radius and height of a cylinder and outputs the total surface area, lateral surface area, and volume of the cylinder. I've typed up the skeleton of the program and I'm just fixing up errors but I can't figure this one out. (The errors are pointed out to the right of the lines through comments in the bottom half of the program)

    #include <iostream>
    #include <cmath>
    using namespace std;

    double totalSurfaceArea(double r, double h);
    double lateralSurfaceArea(double r, double h);
    double volume (double r, double h);

    int main()
    {
    double r, h;
    double tArea, lArea, v;
    const double PI = 3.14159265;

    cout << "This program will calculate the total surface area, lateral surface area, and volume of a right-circular cylinder. \n Please enter the radius and height of the cylinder. \n";
    cin >> r >> h;

    tArea = totalSurfaceArea (r, h);
    lArea = lateralSurfaceArea (r, h);
    v = volume (r, h);

    cout << "The total surface area is: " << tArea << "; the lateral surface area is: " << lArea << "; and the volume is " << v << ".";

    std::cin.clear();
    std::cin.ignore();
    getchar();
    return 0;
    }
    const double PI = 3.14159265;
    double totalSurfaceArea (double r, double h)

    {
    double tArea;

    tArea = 2*PI*r(r+h); //error is in the first r

    return tArea;

    }

    double lateralSurfaceArea (double r, double h)
    {
    double lArea;

    lArea = 2*PI*r*h;

    return lArea;

    }

    double volume (double r, double h)
    {
    double v;

    v = PI(pow(r,2))*h; //error is in the PI

    return v;

    }

    The type of error is "term does not evaluate to a function taking 1 argument" in both cases, and if I hover over the 'r' or 'PI' the error says "expression must have (pointer-to-) function type." I am something of a novice programmer
    in C++, so using simple terms is most helpful. Thanks in advance.
    p.s. Apologies for the poor format copy/paste has left you)

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Pointer error in two lines of code

    r is a double, not a function. See how you're using the asterisk to indicate multiplication? You need to do that consistently. Parens are used to call functions, not to indicate multiplication.
    Last edited by GCDEF; October 12th, 2010 at 10:41 AM.

  3. #3
    Join Date
    Oct 2010
    Posts
    15

    Re: Pointer error in two lines of code

    Thank you for your help! I've got the program running now.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured