C++ 使用未声明的标识符“角度”?

C++ 使用未声明的标识符“角度”?,c++,reference,identifier,reference-parameters,C++,Reference,Identifier,Reference Parameters,我正在制作一个程序,将直角坐标转换为极坐标,每当我运行这个程序时,它都会告诉我角度是未声明的,尽管我确信我已经声明了它。我也知道程序不会返回任何东西,我只想现在就可以运行它 #include <iostream> #include <iomanip> #include <cstdlib> #include <ctime> #include <cmath> using namespace std; double random_floa

我正在制作一个程序,将直角坐标转换为极坐标,每当我运行这个程序时,它都会告诉我角度是未声明的,尽管我确信我已经声明了它。我也知道程序不会返回任何东西,我只想现在就可以运行它

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cmath>

using namespace std;

double random_float(double min, double max);
void rect_to_polar(double x, double y, double &distance, double &angle);

int main() {
    double x, y;
    x = random_float(-1, 1);
    y = random_float(-1, 1);

    rect_to_polar(x, y, distance, angle);
}

double random_float(double min, double max) {
    unsigned int n = 2;
    srand(n);
    return ((double(rand()) / double(RAND_MAX)) * (max - min)) + min;
}


void rect_to_polar(double x, double y, double &distance, double &angle) {
    const double toDegrees = 180.0/3.141593;

    distance = sqrt(x*x + y*y);
    angle = atan(y/x) * toDegrees;

}

您没有在main中声明任何名为angle的内容,但仍然使用了angle的名称。这就是错误

您可能需要仔细阅读。

您应该在主菜单中声明距离和角度

int main() {
    double x, y, angle, distance;
    x = random_float(-1, 1);
    y = random_float(-1, 1);

    rect_to_polar(x, y, distance, angle);
}

你在哪里声明的?你从来没有在主体中声明距离或角度。回答不属于标题。如果某个答案解决了您的问题,请单击旁边的复选标记接受该答案。