Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expression cannot be used as a function

Tags:

c++

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;
}
like image 982
AAA Avatar asked Mar 15 '23 19:03

AAA


2 Answers

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)
like image 186
Alan Stokes Avatar answered Mar 17 '23 08:03

Alan Stokes


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.

like image 30
NoseKnowsAll Avatar answered Mar 17 '23 07:03

NoseKnowsAll