This is my first program.
Written on Notepad++
Compiled from command prompt using MinGW.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include <iostream>
#include <math.h>
using namespace std ;
// define functions //
float calcBearing (float, float) ;// declare calcBearing function
float calcDistance (float, float) ;// declare calcDistance function
float checkBearing (float) ;// declare checkBearing function
float calcBearing (float) ; // declare function for dNorth = 0
// declare global variables
float stnEast , stnNorth , tgtEast , tgtNorth , dEast , dNorth , dist , bearing ;
const double PI = 3.1415926536 ;
int Main ()
{
// Get User input for the Four Variables //
cout << "Enter Station Easting: \t" ;
cin >> stnEast ;
cout << endl << "Enter Station Northing: \t" ;
cin >> stnNorth ;
cout << endl << "Enter Target Easting: \t" ;
cin >> tgtEast ;
cout << endl << "Enter Target Northing: \t" ;
cin >> tgtNorth ;
dEast = ( tgtEast - stnEast ) ;
dNorth = (tgtNorth - stnNorth ) ;
// Call the functions
(dNorth == 0) ? calcBearing (dEast) : calcBearing (dEast , dNorth) ;
checkBearing (bearing) ;
calcDistance (dEast , dNorth );
// Send out results
cout << "Bearing = " << bearing << endl ;
cout << "Distance = " << dist << endl ;
return 0 ;
}
// FUNCTIONS //
float calcDistance ( float dEast , float dNorth )
{
dist = (sqrt ((dEast * dEast) + (dNorth * dNorth ))) ;
return dist ;
}
float calcBearing (float dEast )
{
(dEast > 0) ? bearing = 90 : bearing = 270 ;
return bearing ;
}
float calcBearing (float dEast , float dNorth )
{
if (dNorth < 0 ) { bearing = ( (atan ( dEast / dNorth ) + 180 ) * (PI / 180) ) ; }
if (dNorth > 0 ) { bearing = ( (atan ( dEast / dNorth ) ) * ( PI / 180 ) ) ; }
return bearing ;
}
float checkBearing ( float bearing )
{
if ( bearing < 0 ) { bearing = bearing + 360 ; }
return bearing ;
}
|
Now, please, at this stage try to refrain from pulling the code itself to pieces, as I know that it almost certainly clunky and inexpertly written. I have been teaching myself over the last few weeks and this is a first attempt at a 'proper' program
I have worked through compiling the code, and debugging it until I finally get the expected "... This should work unless it involves constant data structures referencing symbols from auto-imported DLLs." I say expected, as this has been the closing line when compiling all the examples that i have tried.
However, I then get;
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../libmingw32.a(main.o):main.c(.text+0xd2): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
I have tried googling references to winmain@16 both here and the wider web, and turned up articles on Linker errors.
My question, therefore, is;
Is this what is going on? Is the answer in the Linker Errors? I have not come across these and do not (yet) understand the articles that I have seen.
Or is there something else in the code that I am missing?
Once I have an idea of where to look for the answer to that niggle, I would very much appreciate any advice on improving the code itself.
Many Thanks