I was trying to work a problem from the book and decided to compile and run sample code that is already supposed to work. The problem is it doesn't. The concept of breaking these files up is new to me. Can someone please let me know what to do? The idea behind this code is to take 2 files and get them to run with a header. Does it matter which order these are compiled or exactly how does this go? I have read through the book and it isn't really listed. Sample output can be:

Enter the x and y value: 120 80
distance= 144.222, angle = 33.6901 degrees
Next two numbers (q to quit): 120 50
distance= 130, angle= 22.6199 degrees
Next two numbers (q to quit): q

When I try to compile file2.cpp, I get:

[Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status

When I try to compile file1.cpp, I get:

C:\DOCUME~1\STACYA~1\LOCALS~1\Temp\ccSGbaaa.o(.text+0x1a0) In function `main':   
[Linker error] undefined reference to `rect_to_polar(rect)' 
[Linker error] undefined reference to `show_polar(polar)' 
 C:\DOCUME~1\STACYA~1\LOCALS~1\Temp\ccSGbaaa.o(.text+0x1a0) ld returned 1 exit status 


#ifndef COORDIN_H_
#define COORDIN_H_

struct polar
       double distance;
       double angle;
       struct rect
              double x;
              double y;
         polar rect_to_polar(rect xypos);
         void show_polar(polar dapos);


#include <iostream>
#include "coordin.h"
using namespace std;
int main()
    rect rplace;
    polar pplace;
    cout <<"Enter the x and y values: ";
    while(cin >> rplace.x >> rplace.y)
              pplace = rect_to_polar(rplace);
              cout << "Next two numbers (q to quit): ";
    cout << "Bye!\n";
    return EXIT_SUCCESS;


#include <cmath>
#include "coordin.h"

polar rect_to_polar(rect xypos)
      using namespace std;
      polar answer;

      answer.distance = sqrt(xypos.x*xypos.x+xypos.y*xypos.y);
      return answer;

void show_polar(polar dapos)
      using namespace std;
      const double Rad_to_deg=57.29577951;

      cout <<"distance= " << dapos.distance;
      cout <<", angle= " << dapos.angle*Rad_to_deg;
      cout <<" degrees\n";

I am using Dev-C++.

Any help will be greatly appreciated.

Did u save the header & the implementation files in the same folder?

The problem isn't with the addition of your headers files but with your code!

Yup, I can see them now....Thanks iamthwee

How do you save it in the same folder?

What is wrong with the code? This is straight from the book.


Hey folks, I got this one figured out. Sorry for asking. I will try harder next time.