Help!!! I don't know why my program won't work.

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

void getPoint (double&, double&, double&, double &);
void calcDistance (double, double, double, double);
void findMidpoint (double, double, double, double, double&, double&);

bool findSlope (double, double, double, double, double&);
void outputResults (double, double, double, double, double, double, double);

int main()
{
double x1, y1, x2, y2, distance, midpointX, midpointY, slope, midpoint;

getPoint(x1, y1, x2, y2);
calcDistance(x1, y1, x2, y2);


findMidpoint (x1, y1, x2, y2, midpointX, midpointY);
findSlope (x1, y1, x2, y2, slope);
outputResults (x1, y1, x2, y2, distance, midpoint, slope);

return 0;
}

void getPoint(double& x1, double& y1, double& x2, double & y2)
{
cout << "Enter x1: ";
cin >> x1;
cout << "Enter y1: ";
cin >> y1;
cout << "Enter x2: ";
cin >> x2;
cout << "Enter y2: ";
cin >> y2;
}

void calcDistance (double x1, double y1, double x2, double y2)
{
double distance;

distance = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
distance = sqrt(distance);

cout << "Distance is: " << distance << endl;
}

void findMidpoint (double x1, double y1, double x2, double y2, double midpointX, double midpointY)
{
midpointX = (x1 + x2) / 2;
midpointY = (y1 + y2) / 2;

cout << "Midpoint: (" << midpointX << "," << midpointY << ")/n";
}

bool findSlope (double x1, double y1, double x2, double y2, double& slope)
{
bool undefined = false;
if (x2 - x1 == 0) undefined = true;
else slope = (y2 - y1) / (x2 - x1);
if (undefined == false)
cout << "Slope is: " << slope << endl;
else cout << "Slope is: " << "undefined" << endl;

}

void outputResults (double x1, double y1, double x2, double y2, double distance, double midpoint, double slope)
{
cout << "Points: " << "(" << x1 << "," << y1 << ")" << "(" << x2 << "," << y2 << ")" << endl;
cout << "Distance: " << distance << endl;
cout << "Midpoint; " << midpoint << endl;
cout << "Slope: " << slope << endl;
}
please use the code-tag ([code ]here comes your code[/code ])

you forgot the & in findMindpoint for the last 2 parameters and you declared findSlope a bool, make it void because it doesn't return anything

also note that you never assigned a value to "midpoint", you have to pass "midpointX" and "midpointY"
furthermore you never assign a value to "distance"
Topic archived. No new replies allowed.