2016-04-04 51 views
0

想要將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; 
} 
+1

你在你的showPolarCoord()函數中究竟想要做什麼?看看你的cout聲明,打印'showPolarCoord'不是你正在尋找的 –

+0

如果你永遠不會叫'showPolarCoord',你期望它如何運行?同樣'cout <<「極座標是:」<< showPolarCoord << endl;'打印函數的地址而不是值。 – NathanOliver

+0

@NathanOliver如何編輯它以打印值? –

回答

1

問題之一: 在你showPolarCoord(),你cout語句打印功能的地址。當你輸入函數的名字時,會發生這種情況,這最終不是你想要打印的。

你需要的是這樣的事情(除了把正確的公式計算的極角出角度和半徑):

void showPolarCoord(double radius, double angle)   
{ 
    cout << "The polar coordinates are: " << radius * angle << endl; 
} 

問題二: 您需要調用的函數showPolarCoord()main()實際使用其功能。但你沒有。

問題三: 這是一團糟。在main(),你想用這兩個語句來實現什麼?

while(count < SIZE && (x[count -1] != 0) && (y[count -1] != 0)); 
return count; 
+1

OP還需要調用該函數。他們不在他們當前的代碼中。 – NathanOliver

+0

正確。謝謝,我將編輯。 –

+0

雅,我現在意識到,我沒有叫它。我真的不確定如何稱呼這一個,因爲我不完全理解與之相關的數學。我一直在使用一個朋友,一直在幫助我得到這個(引導我完成它,而不僅僅是爲我寫這篇文章。)據說,我不知道我在處理第3期問題。 –