I am very new to computer programming and am struggling with my Computer Science class...
I have been working on this program all week long...
My assignment is to ;
Write a float function that will have four float parameters. The four parameters represent two Cartesian points, 2 x's and 2 y's. Return the distance between the two points. It involves a square root.
Write a main function which will ask the user for 2 points (4 numbers), decide whether the distance between them is within 25 units ("hit"), exactly 25 units ("on the rim"), or more than 25 units away ("missed"). You must call the function written previously. Use the fewest possible number of if statements and comparisons to do this efficiently. Output this message on the console window (use "cout").
Then add in some code to use the first point entered as the center of a circle, and draw a circle that is 25 units in radius. Draw a small circle at the location of the other point. Output the classification of the distance on the graphics screen (look up the function "outtextxy".). The use of the word "units" does not imply any conversions needed, they are just 'spaces on the plane' or pixels in the graphics sense.
This is what I have gotten so far... I honestly have no idea how close I am to finishing up
#include <iostream>
#include <cmath>
#include "graphics.h"
using namespace std;
float point (float x1, float x2, float y1, float y2);
float point (float x1, float x2, float y1, float y2)
{
if (distance < 25.0)
return "hit";
else if (distance == 25.0,)
return "on the rim";
else if (distance > 25.0)
return "miss";
}
int main ()
{
float x1;
float x2;
float y1;
float y2;
float distance;
float squareroot;
cout << "Please enter the cordinates for the first point.";
cin >> x1 >> y1;
cout << "Now enter the cordinates for the second point.";
cin >> x2 >> y2;
squareroot = pow (float(x2-x1),2) + pow (float(y2-y1),2);
distance = squareroot/squareroot;
cout<< point <<endl;
return 0;
}
Any ideas of what I should do?
Thanks -
~mason