【问题标题】:"Called object 'int' is not a function or a function pointer" error“被调用的对象'int'不是函数或函数指针”错误
【发布时间】:2014-01-18 20:44:15
【问题描述】:

好的,所以我很新而且没有经验,所以这个问题很可能很愚蠢,但我试图查找解决方案但失败了,所以我想我会在这里尝试为什么不。

我正在尝试编写一个程序,它获取三角形的边并输出面积、周长以及它是否是直角三角形。周界工作正常,但是当我尝试定义 s 和区域时,它给了我错误消息“调用的对象'int'不是函数或函数指针”

这是我的代码:

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

//area = sqrt(s(s-a)(s-b)(s-c))

int main()
{
int a;
int b;
int c;
int perimeter;
int area;
int s;


//ask for triangle sides
cout << "Input triangle sides (smallest to largest) " << endl;
cin >> a >> b >> c;

perimeter = a + b + c;

s =(a+b+c)/2;

area = sqrt(s(s-a)(s-b)(s-c))


//This one says 'Expression is not assignable' I don't see why it wouldn't work...

if ((c*c)-((a*a)+(b*b))= 0 )
    cout << "Right triangle" << endl; 




cout << "Side A: " << a << endl;
cout << "Side B: " << b << endl;
cout << "Side C: " << c << endl;
cout << "The perimeter is " << perimeter << endl;
cout << "The area is " << area << endl;



return 0;

}

任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 你知道= vesus == 的区别吗?

标签: c++ macos xcode5


【解决方案1】:
  1. 你需要明确写*

    area = sqrt(s*(s-a)*(s-b)*(s-c));

你也忘记了最后的;

  1. 您可能需要== 进行比较(+ 您可以去掉额外的括号):

    if ( c*c - a*a - b*b == 0 )

【讨论】:

    【解决方案2】:

    C++ 中没有隐式乘法:使用sqrt(s*(s-a)*(s-b)*(s-c))

    【讨论】:

      【解决方案3】:

      与传统的数学符号不同,乘法在 C++ 中并不隐含。要乘以数字,请使用 * 运算符

      area = sqrt(s*(s-a)*(s-b)*(s-c));
      

      【讨论】:

        【解决方案4】:

        与数学不同,乘法总是需要一个“*”,而相等性测试是用“==,而不是“=”完成的。

        你应该读一本像样的书。

        【讨论】:

          猜你喜欢
          • 2021-11-21
          • 2012-05-28
          • 1970-01-01
          • 2018-06-02
          • 2022-10-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多