想要將x,y座標轉換爲極座標。代碼循環請求x和y的初始輸入。它從不輸出極座標。代碼不輸出,循環輸入語句
#include <iostream>
#include <math.h>
using namespace std;
int getrec(double x[], double y[]);
void polar(double x, double y, double& r, double& theta);
void showPolarCoord(double radius, double angle);
const int SIZE = 100;
const double toDegrees = 180.0/3.1415926;
int main()
{
double x[SIZE];
double y[SIZE];
double distance[SIZE];
double angle[SIZE];
double x_same[SIZE];
double y_same[SIZE];
int count = getrec(x,y);
for (int i=0; i < count; i++)
{
x_same[i] = x[i] + 6;
y_same[i] = y[i] + 2;
}
for(int i=0; i < count; i++)
{
polar (x_same[i], y_same[i], distance[i], angle[i]);
}
}
int getrec(double x[], double y[])
{ int count = 0;
do
{ cout << "Enter the x coordinate: ";
cin >> x[count];
cout << "Enter the y coordinate: ";
cin >> y[count];
count++;
}
while(count < SIZE && (x[count -1] != 0) && (y[count -1] != 0));
return count;
}
void polar(double x, double y, double& r, double& theta)
{
r = sqrt((pow(x,2))+(pow(y,2)));
theta = atan(y/x) * toDegrees;
return;
}
void showPolarCoord(double radius, double angle)
{
cout << "The polar coordinates are: " << showPolarCoord << endl;
return;
}
你在你的showPolarCoord()函數中究竟想要做什麼?看看你的cout聲明,打印'showPolarCoord'不是你正在尋找的 –
如果你永遠不會叫'showPolarCoord',你期望它如何運行?同樣'cout <<「極座標是:」<< showPolarCoord << endl;'打印函數的地址而不是值。 – NathanOliver
@NathanOliver如何編輯它以打印值? –