Geometry: Distance of Two Points

less than 1 minute read

The code has been modified slightly and now uploaded to the site.

Question

Question

<— Return Home

215.cpp

#include <iostream>
#include <math.h>
using namespace std;

int main(){
    double x;
    double y;
    double x2;
    double y2;
    double distanceX;
    double distanceY;
    double distance;

    std::cout << "Enter x1 and y1: \n";
    std::cin >> x;
    std::cin >> y;

    std::cout << "Enter x2 and y2: \n";
    std::cin >> x2;
    std::cin >> y2;

    distanceX = pow(x2 - x, 2);
    std::cout << "The distanceX is: " << distanceX << "\n";
    distanceY = pow(y2 - y, 2);
    std::cout << "The distanceY is: " << distanceY << "\n";
    distance = pow((distanceX + distanceY), (0.5));

    std::cout << "The distance between the two points is " << distance;
}

<— Return Home

Input (215input.txt)

1.5
-3.4
4
5

<— Return Home