简体   繁体   English

代码不输出,循环输入语句

[英]Code not outputting, looping input statements

Looking to convert x,y coordinates to polar. 希望将x,y坐标转换为极坐标。 Code is looping asking for the initial inputs for the x and y. 代码正在循环,要求x和y的初始输入。 It never outputs what the polar coordinates are. 它从不输出极坐标是什么。

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

Issue one: In your showPolarCoord() , your cout statement is printing the address of the function. 问题一:showPolarCoord() ,您的cout语句正在打印函数的地址。 This happens when you put the name of the function, which is eventually not what you want to print. 当您输入该函数的名称时会发生这种情况,而该名称最终并不是您要打印的。

What you want is something like this (except to put the right equation for calculating polar angles out of an angle and a radius): 您想要的是这样的东西(除了要使用正确的公式来计算角度和半径之外的极角):

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

Issue two: You need to call the function showPolarCoord() in main() to actually use its functionality. 问题二:您需要在main()调用函数showPolarCoord() main()才能真正使用其功能。 But you did not. 但是你没有。

Issue three: This is a mess. 问题三:这是一团糟。 In main() , what are you trying to achieve using these two statements? main() ,您试图使用这两个语句来实现什么?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM