gpt4 book ai didi

c++ - 对 `computeArea(int, int, int)' 的 undefined reference

转载 作者:行者123 更新时间:2023-11-28 06:16:11 25 4
gpt4 key购买 nike

<分区>

我正在尝试测试计算多边形面积的公式。但是,我似乎无法编译。

#include <iostream>

using namespace std;

int main (int argc, char** argv)
{
int xvalue[12];
int yvalue[12];

int X = 0;
int Y = 0;

double area = 0.0;

double computeArea(int *, int *, int);

for (int i=0; i<12; i++)
{
cout << "\nPlease enter x-ordinate of pt " << i+1 << ": ";
cin >> X;
xvalue[i] = X;

cout << "Please enter y-ordinate of pt " << i+1 << ": ";
cin >> Y;
yvalue[i] = Y;
}

/*for (int i=0; i<12; i++)
{
computeArea(xvalue[i], yvalue[i], 12);
}*/

area = computeArea(xvalue, yvalue, 12);

cout << "Your area is: " << area << endl;

}

double computeArea(int *X, int *Y, int points)
{
double area;
int i;
int j=points-1;

for (i=0; i<points; i++)
{
area+=(X[j]+X[i])*(Y[j]-Y[i]);
j=i;
}

return area*.5;

}

感谢 R Sahu,脚本现在可以编译,所以我输入了 12 个坐标,它们是:

15, 3
15, 5
13, 5
13, 7
15, 7
15, 9
17, 9
17, 7
19, 7
19, 5
17, 5
17, 3

但是结果出来的是240,这是错误的,应该是20

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com