【问题标题】:Undeclared identifier/array未声明的标识符/数组
【发布时间】:2014-01-15 09:23:53
【问题描述】:

我收到此错误 array1 undeclared (first use this function) , array1 undeclared (first use this function)[Warning] 从 double 转换为 int

代码如下:

#include<conio.h>
#include<math.h>
using namespace std;

int main(){
double dist(double array1[4], double array2[4]);
{
    double Sum;
    double distance;

    for(int i=0;i<4;i++)
    {
        cout<<"Enter value of first coordinate";
        cin >> array1[i];
        cout<<"Enter value of second coordinate";
        cin >> array2[i];

        Sum = Sum + pow((array1[i]-array2[i]),2.0);
        distance = sqrt(Sum);
    }
        cout << "DISTANCE: " << distance;
    return distance;
}
}

我不知道在哪里修复此错误。有人可以帮忙吗?

【问题讨论】:

  • 除了@XiaogeSu 已经提到的:你正在使用Sum 未初始化,使用double Sum();double Sum = 0.0; 进行初始化。

标签: c++ arrays


【解决方案1】:
  1. 几个世纪以来我都没有见过conio.h。我假设它是 Turbo C++?请改用#include &lt;iostream&gt;
  2. 您在main 内声明函数dist。除非您使用 C++11 lambda 语法,否则 C++ 不允许这样做。将dist移出main,去掉函数声明行的分号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 2021-06-07
    • 2016-04-09
    • 2020-12-09
    • 2016-04-22
    相关资源
    最近更新 更多