-4

我正在制作一个将直角坐标转换为极坐标的程序,每当我运行该程序时,它都会告诉我“角度”是未声明的,即使我确信我已经声明了它。我也知道该程序没有返回任何内容,我只想现在能够运行它。

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

}
4

2 回答 2

3

你没有angle在你的中声明任何调用的东西main(),但仍然在angle那里使用了这个名字。因此错误。

您可能想阅读范围

于 2015-02-22T21:56:14.110 回答
0

你应该在你的主要声明distanceangle

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

    rect_to_polar(x, y, distance, angle);
}
于 2015-02-22T21:56:17.893 回答