加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 表达式不能用作函数

发布时间:2020-12-16 09:59:06 所属栏目:百科 来源:网络整理
导读:在第23行,它说表达式不能用作函数.我不明白这意味着什么.我不确定它要求我改变什么,并希望得到一些帮助.起初我以为它可能是我在标题中预定义的M_PI常量,我改为PI并直接在代码中定义它但是没有用. #include "std_lib_facilities_4.h"int main() { const doubl
在第23行,它说表达式不能用作函数.我不明白这意味着什么.我不确定它要求我改变什么,并希望得到一些帮助.起初我以为它可能是我在标题中预定义的M_PI常量,我改为PI并直接在代码中定义它但是没有用.

#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: nn";

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

解决方法

在数学中,360.0(PI * radius)显然是乘法.

但在C语言中,这显然是试图将360.0称为函数 – 这注定要失败. a(b)总是函数调用.

你需要明确你的操作符:

360.0 * (PI * radius)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读