简体   繁体   中英

Expression cannot be used as a function

On line 23 it' saying expression cannot be used as a function. I'm not understanding what it means. I'm not sure what its asking me to change and would like some help. At first I thought it might have been my predefined M_PI constant in my header that I changed to PI and directly defined it in the code but that didn't work.

#include "std_lib_facilities_4.h"
int main() {

    const double PI = 3.141592653589793238463;

    //formula for area of a circle is pi*r^2    
    //area of a 14" circle is 153.94"

    cout << "Enter cord length in inches: \n\n";

    double chord_length;

    while(cin >> chord_length) {

        double radius = 7.0;
        double angle_of_sect = (asin((chord_length / 2.0) / radius)) * 2.0;
        double area_of_sect = (angle_of_sect / 360.0(PI * radius));
        double area_of_seg = area_of_sect - (((chord_length / 2.0) * radius) * 2.0);
        double perc_of_pizza = (100.0 * area_of_seg) / 153.94;


        if(chord_length > 14) {
            cout << "Chord Length Too Long \n";
        } else if(chord_length <= 0) {
            cout << "Chord Length Too Small \n";
        }

        cout << "\nSegment area is equal to: " << perc_of_pizza << ".\n";

    }

    return 0;
}

In mathematics, 360.0(PI * radius) is clearly multiplication.

But in C++ it is just as clearly an attempt to call 360.0 as a function - which is doomed to failure. a(b) is always a function call.

You need to be explicit with your operators:

360.0 * (PI * radius)

You forgot a * sign.

(angle_of_sect / 360.0(PI * radius));

should be

(angle_of_sect / 360.0*(PI * radius));

It's attempting to call function 360.0 which obviously isn't a function.

In 23, Instead

(angle_of_sect / 360.0(PI * radius));

will be

(angle_of_sect / 360.0*(PI * radius));

You forget to give * sign.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM