--Originally published at OlafGC / Class #TC1017
Here we are: the final exam. In this video/tutorial, I’m going to explain how to easily write the function for the third question of our final exam. Here is the code and enjoy the ride!
#include <iostream>
#include <cmath>
using namespace std;
float distancia(float x1, float x2, float y1, float y2)
{
float distancia;
distancia = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));
return distancia;
}
int main()
{
float x1, x2, y1, y2;
cout<<“Please insert four numers in order.”<<endl;
cout<<“X1: “;cin>>x1;
cout<<“X2: “;cin>>x2;
cout<<“Y1: “;cin>>y1;
cout<<“Y2: “;cin>>y2;
cout<<“The distance is “<<distancia(x1, x2, y1, y2)<<“.”<<endl;
return 0;
}