Program compiles and runs no problem but closes right away when finished. Any help is much appreciated. Heres the code:
Code:
#include <iostream>
#include <cmath>
using namespace std;
double calcDistance(double,double, double, double);
float calcKilometers(float, const float) ;
int main()
{ char choice;
cout << "1.Calculate distance between two points?"<< endl;
cout<<"2.Miles to Kilometers?"<< endl;
cin >> choice;
if (choice=='1')
{
double x1;
double y1;
double x2;
double y2;
cout << "Enter X coordinate for first point:"<< endl;
cin >> x1;
cout << "Enter Y coordiante for first point:"<<endl;
cin >> y1;
cout << "Enter X coordinate for second point:"<< endl;
cin >> x2;
cout << "Enter Y coordiante for second point:"<<endl;
cin >> y2;
cout << "The distance between those points is " <<calcDistance(x1,y1,x2,y2)<<endl;
return;
}
else if (choice=='2')
{
const float KMperMile= 1.609;
float miles;
cout << "How many miles?" << endl;
cin >> miles;
cout << "It is " <<calcKilometers(KMperMile,miles) << endl;
return;
}
system("PAUSE");
}
double calcDistance(double x1,double y1, double x2, double y2)
{
double distancee;
distancee = sqrt (((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1))) ;
cout << "The distance between those points is " <<distancee<< endl;
return distancee;
}
float calcKilometers(const float KMperMile,float miles)
{
float solution;
solution = miles * KMperMile;
return solution;
}