#include <iostream>
#include <cmath> // for std::abs
// Function that returns the distance between two decimal numbers
double distanceBetween(double a, double b) {
// The distance is the absolute value of the difference
return std::abs(a - b);
}
int main() {
// Test values
double x1 = 100, y1 = 45;
double x2 = 100, y2 = -15;
double x3 = -100, y3 = -125;
double x4 = -600, y4 = 100;
// Print results
std::cout << "Distance between " << x1 << " and " << y1 << " = "
<< distanceBetween(x1, y1) << std::endl;
std::cout << "Distance between " << x2 << " and " << y2 << " = "
<< distanceBetween(x2, y2) << std::endl;
std::cout << "Distance between " << x3 << " and " << y3 << " = "
<< distanceBetween(x3, y3) << std::endl;
std::cout << "Distance between " << x4 << " and " << y4 << " = "
<< distanceBetween(x4, y4) << std::endl;
}
/*
run:
Distance between 100 and 45 = 55
Distance between 100 and -15 = 115
Distance between -100 and -125 = 25
Distance between -600 and 100 = 700
*/