1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
#include <cmath>
using namespace std;
double distance(double x1, double x2, double y1, double y2)
{
return sqrt ((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
}
int main()
{
double linkX, linkY;
cout <<"== Zelda (version 0.000001) ==\n";
cout <<"What is the position of our hero, Link?\n";
cout <<"Enter X and Y coordinated separated by a space.\n";
cin >> linkX >> linkY;
cout <<"Sword is at (5.0, 3.0). Distance from Link: "
<< distance(linkX, 5.0, linkY, 3.0) << "\n";
cout <<"Heart is at (-3.125, 0). Distance from Link: "
<< distance(linkX, -3.125, linkY, 0) << "\n";
cout <<"Triforce is at (1.5, 8.1). Distance from Link: "
<< distance(linkX, 1.5, linkY, 8.1) << "\n";
return 0;
}
|