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 -

8 Years
Discussion Span
Last Post by firstPerson

Thanks a bunch, now I just need to find out how to get it to draw a circle :(


Your professor gave you a function free of charge called outtextxy( ). Worst case scenario, why not just call outtextxy() individually for every ascii character that you will to output on the dos console to draw your circle?

This may seem inefficient, but here is a way to at least make your code look 'better':

struct coord{
     int x;
     int y;

void draw_circle();

     coord point[80];

     //This is where it sucks..  it's up to you to come up with this list of coordinates 
     //through trial-and-error.
     point[0].x = 10; point[0].y = 15;
     point[1].x = 11; point[1].y = 14;
     point[2].x = 12; point[2].y = 14;
     point[3].x = 13; point[3].y = 13;
     point[4].x = 14; point[4].y = 13;
     point[79].x = 9; point[79].y = 16;

void draw_circle()
     for(int i=0; i<80; i++)
          outtextxy(point[i].x, point[i].y);

Although this looks brutally painful, I believe this is an appropriate technique for your level of academics. This will involve a lot of trial-and-error (having to recompile and run your program after every 'guess' of where to plot the next point for your circle) but after you've done the hard part of getting all those coordinate positions, the rest is easy.

One thing that will ease the pain: buy some graph paper. Once you get your circle started, it will be quite easy to forecast the majority of the remainder of coordinates for your ascii circle. This will help you ensure that all points are roughly at a 25 unit radius.

Other alternatives would be to look online for information on how to draw an ascii circle... your professor would undoubtedly ask where you got this information as some of these functions are quite complex... specifically the Bresenham Circle.

Edited by Clinton Portis: n/a


Not exactly sure if this will help but the equation to a circle is :

//Cartesian coordinate
X^2 + Y^2 = R^2
//polar coordinate
//R = radius
sin^2(x)* R + cos^2(X) * R = 1
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.