cant get this to run on my compiler, any idea of where im going wrong in my code here, any help would be so helpful

#define pi 3.1415926535897

#include<iostream>
#include<math.h>



using namespace std;
int main ()
{
double lat1=pi/180;
double long1=pi/180;
double lat2=pi/180;
double long2=pi/180; // initilaise values
double latz = 0;
double longz = 0;
double a = 0;
double c = 0;
double d = 0;
double x = 0;
double y = 0;

cout << "enter in radians " << endl;
cin >> lat1;
cin >> long1;
cin >> lat2;
cin >> long2;


latz = (lat2 - lat1);
longz = (long2 - long1);
cout << latz << endl;
cout << longz << endl;
a = sin(latz/2) * sin(latz/2) + cos(lat1) * cos(lat2)
* sin(longz/2) * sin(longz/2);

cout << " A is equal to: " << a << endl;
x = sqrt(a);
cout << x << endl;
y = sqrt(1-a);
cout << y << endl;
c = 2* atan2(x ,y); 


cout << " C is equal to: " << c << endl;

d = 6371 * c; //greatcircle distance in km

cout << " and D is: " << d <<"km";
char in;
cin >> in;
}

Recommended Answers

All 5 Replies

What compiler are you using and what error message are you getting?

im using microsoft visual studio and visual command prompt, dont have access to a computer atm, but i think its the line 10-14 code, maybe im messed up the radians part, line no.10 sounds familiar?

i may be wrong as I use gcc most of the time but doesn't visual studio like int argc and char const ** or similar in the arguments of the main function for a console program. Are you saying you get the wrong answer or that the program doesn't compile? What error message did you get?

In VC++ 2010 it compiles and runs.

Do you have some sample input and the corresponding output you expect?

gazzatav: The use of the command line arguments for main are optional. If your program doesn't expect arguments, you need not enter them in your code. It is not a compiler dependant thing.

vmanes: I know the use of command line arguments for main are optional. I've read about it being a problem for some compilers/ide setups (of course I can't find the article now!). We don't know which version pjh-10 is using, his setup or anything. I can compile and run this fine with g++. Don't know if the OP is saying the maths is wrong or the compilation. Lines 10-14 that he mentions initialize values that he later clobbers from line 24 onwards. I suspect pjh-10 wants us to fix his mathematics not the compilation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.