Your input format will be : name x-value y-value
i my code i have so far is below but doesnt work correctly ...please any help
# include <iostream>
# include <cmath>
# include <iomanip>
using namespace std;struct Range
{
double X_coordinate;
double Y_coordinate;
};
double length[49995500];
int main()
{
Range point[10000];
int Num_Points;
char letter_character;
/*************************
* Get user input *
*************************/
cout << "enter number of coordinates you want compared: ";
cin>>Num_Points;
if (Num_Points <= 1)
{return 0;}
int counter=0;
for (int i=0;i<Num_Points;i++)
{cout <<"\nNow enter a letter character to label coordinates and enter your (x,y)points separated :" << endl;
cin >> letter_character;
cin >> point[i].X_coordinate;
cin >> point[i].Y_coordinate;}
double low=10000;
for (int i=0;i<Num_Points;i++)
{
for (int j=i;j<Num_Points-1;j++)
{
double X=0,Y=0;
X = point[i].X_coordinate - point[j+1].X_coordinate;
Y = point[i].Y_coordinate - point[j+1].Y_coordinate;
if ( X < 0 )
X *= -1;
if ( Y < 0 )
Y *= -1;
double distance;
distance = pow(X,2) + pow(Y,2);
length[counter] = sqrt(distance);
if (length[counter] < low)
low = length[counter];
counter++;
}
}
if (low >= 10000)
{
cout<<"endlessness"<<endl;
}
cout << letter_character << " has the smallest distance of : "<< low << endl;
return 0;
}
***
This post has been edited by Skydiver: 19 February 2013 - 04:37 PM
Reason for edit:: Put code into code tags. Learn to do it yourself in the future.

New Topic/Question
Reply



MultiQuote




|