Need some help !

I am suppose to find the radius using the formula for the distance of two points.
the formula is sqrt(x2-x1)^2 + (y2-y1)^2
the function accepts 4 float numbers and returns 1 float number.


This is the code I have written so far, but it wont execute correctly. It only asks for the input and doesn't execute the function.



#include<iostream>
#include<cmath>
using namespace std;


//the function prototype goes here

int radius(float, float, float, float);

int main()

{
float x1, y1, x2, y2;
float r;

cout << "Enter 4 numbers corresponding to the" << endl;
cout << "coordinates of two points : ";
cin >> x1 >> y1 >> x2 >> y2;

r = radius(x1, y1, x2, y2);

cout << "The radius is: " << r;

return 0;
}

//The code of the function goes here

int radius(float a1, float b1, float a2, float b2)
{
return sqrt(pow(a2 - a1, 2.0) + pow(b2 - b1, 2.0));

}


you need a cin.ignore();to remove the newline character left in the input stream after r = radius(x1, y1, x2, y2);
btw, your radius() function is a bit confusing, the co-ordinates of each point is non-contiguous. rather it'd be more realistic to declare struct Point with data-members x-cord, y-cord etc and a distance function for the Euclidean distance b/w 2 Point objects
Thank You !
Topic archived. No new replies allowed.