0

Looking to convert x,y coordinates to polar. Code is looping asking for the initial inputs for the x and 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;
} 
3
  • 1
    What are you exactly trying to do in your showPolarCoord() function? Look at your cout statement, printing 'showPolarCoord' is not what you are looking for Commented Apr 4, 2016 at 15:05
  • If you never call showPolarCoord how do you expect it to run? Also cout << "The polar coordinates are: " << showPolarCoord << endl; prints the address of the function not the values. Commented Apr 4, 2016 at 15:06
  • @NathanOliver How would I edit it to print the values? Commented Apr 4, 2016 at 15:16

1 Answer 1

1

Issue one: In your showPolarCoord(), your cout statement is printing the address of the function. 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. But you did not.

Issue three: This is a mess. In main(), what are you trying to achieve using these two statements?

while(count < SIZE && (x[count -1] != 0) && (y[count -1] != 0));
return count;
Sign up to request clarification or add additional context in comments.

5 Comments

The OP also needs to call the function. They do not in their current code.
Ya, I realize now that I haven't called it. I'm honestly uncertain how to call this one as I don't entirely understand the math associated with it. I've been using a friend that's been helping me get this (guiding me through it, not just writing it for me.) With that said, I have no idea what I'm doing with issue 3.
@jonathanhall We can't help if you have no idea what is going on as a whole. However, my advice is to Step-Over your code (F10 in Visual Studio), and follow its control/logic and try to change the code in a way that matches what you are trying to achieve out of this (Assignment?). Feel free to edit your OP and/or ask another question.
@FirstStep I did state what the goal of the program was. >Looking to convert x,y coordinates to polar.
@jonathanHall, this doesn't get you a free answer. Here they help but they don't do it for you. Now, My answer answers this question. Please mark it and move on. Create a new question AFTER you debug your program and get a good knowledge of it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.