c++ - Errors in the calculator program -



c++ - Errors in the calculator program -

i'm working programme calculate distance between 2 geographical points on earth's surface. im pretty new @ c++ , apologize if english language bad

any suggestions on how can content @ programme @ bottom 1 @ top no errors?

this programme doesn`t work.

#include <iostream> #include <cstdio> #include <cmath> using namespace std; int main () double getdistance(double x1,double y1,double x2,double y2) { const double pi = 3.1415927; double radius, sum; int exit = 1; char choice; while (exit == 1) { cout << "**** calculate programme **** \n\n" << "1. volume\n" << "2. div\n" << "3. calculate 2 geographical points\n" << "4. working\n\n" << "5. quit program\n\n"; cout << "choose 1 of options , write here: "; cin >> choice; switch (choice) { // case '1': float volume (float radius); { cout << "radius want calculate: " << endl; cin >> radius; sum = 4.0/3.0 * pi * pow (radius, 3); cout << "volume: " << sum << endl; } break; // case '2': cout<<"div \n"; break; // case '3': radius=6371; // radius km double pi=3.14159265; double x1,y1,x2,y2; // x og y coords x1=(x1/180)*pi; y1=(y1/180)*pi; x2=(x2/180)*pi; y2=(y2/180)*pi; // if else if (x1==x2 && y1==y2) homecoming 0; else { if ((sin(x2)*sin(x1)+cos(x2)*cos(x1)*cos(y2-y1))>1) homecoming radius*acos(1.0); else homecoming radius*acos(sin(x2)*sin(x1)+cos(x2)*cos(x1)*cos(y2-y1)); // double x1,y1,x2,y2; cout<<"write coords calculate distance from: \n"; cin>>x1>>y1; cin>>x2>>y2; cout<<"distance in km : \n"; cout<<getdistance(x1,y1,x2,y2)<<endl; homecoming 0; } break; case '4': cout<<"working \n"; break; // case '5': exit = 0; break; default: exit = 0; cout << "error!"; } // switch quit } // while quit homecoming 0; }

this programme work , have set within case 3 in programme above.

# include <iostream> # include <cstdio> # include <cmath> using namespace std; double getdistance(double x1,double y1,double x2,double y2) { double radius; radius=6371; // radius km double pi=3.14159265; // x og y coord x1=(x1/180)*pi; y1=(y1/180)*pi; x2=(x2/180)*pi; y2=(y2/180)*pi; if (x1==x2 && y1==y2) homecoming 0; else { if ((sin(x2)*sin(x1)+cos(x2)*cos(x1)*cos(y2-y1))>1) homecoming radius*acos(1.0); else homecoming radius*acos(sin(x2)*sin(x1)+cos(x2)*cos(x1)*cos(y2-y1)); } } int main() { double x1,y1,x2,y2; cout<<"write coords calculate distance from: \n"; cin>>x1>>y1; cin>>x2>>y2; cout<<"distance in km : \n"; cout<<getdistance(x1,y1,x2,y2)<<endl; homecoming 0; }

the programme seems fine. switch statements, work integers or single character values. switch not compare strings or floating-point numbers. perhaps posting total code of alternative help identify problem.

edit

int main () double getdistance(double x1,double y1,double x2,double y2) {

this wrong. when declare functions must declare them before main , define them before or after main, although conventionally define them after.

i.e.

//#include directives double getdistance(double x1,double y1,double x2,double y2); int main() { // code main() } double getdistance(double x1,double y1,double x2,double y2) { //code function }

c++ haversine

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -