I have to do my homework for passing the course :)
The question is that;
Firstly the starting point is (x1,y1) we get these values from user and
we get a lot of two dimensional points from user.If a point is far away from the center point of the points, it is discarded and displayed as a outlier point. Otherwise a new center point is calculated.
The question's
Inputs:

• Delta( Δ ) distance for outliers
• Get two dimensional points (x,y)
• point (0,0) ends application

Outputs:

• Display center point (x,y) at each new point.
• If a point (x,y) is found to be outlier give a message
should be like that.I developed such a program but it doesnt work truely.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double findDelta(int x1,int x2,int y1,int y2);  //function prototype for distance

double findNewCenter(int x1,int x2,int y1,int y2);  //function prototype for new center


int main(int argc, char *argv[])
{
  
  
  
  double distance; // the distance between two points
  int x1,x2,y1,y2;  // these are variables for dimensionals
  int tempx1,tempy1;
  
  printf("Enter the x point\n");  // we specify first point
  scanf("%d",&x1);
  
  printf("Enter the y point\n");  // we specify second point
  scanf("%d",&y1);
  
  do{                             
  
  printf("Enter another x point\n");  // getting new x point
  scanf("%d",&x2);
  
  printf("Enter another y point\n");   // getting new y point
  scanf("%d",&y2);
                           
  
  findNewCenter(x1,x2,y1,y2);          // function for finding new center
  findDelta(x1,x2,y1,y2);             // function for finding new distance
  
}while(x1!=0 && x2!=0);


  system("PAUSE");	
  return 0;
}


double findDelta(int x1,int x2,int y1,int y2)
{
     double result,pow1,pow2;             // result is distance
     pow1=pow(x2,2)-pow(x1,2);            // pow1 is first points' powers
     pow2=pow(y2,2)-pow(y1,2);             // pow2 is second points' powers
     result=sqrt(abs(pow1)+abs(pow2));
     printf("Distance=%f\n",result);       // it shows the distance 
}
double findNewCenter(int x1,int x2,int y1,int y2)
{
     double cx,cy;                            // center points' variables
     cx=(x1+x2)/2;                            // finding center's x axis
     cy=(y1+y2)/2;                            //  finding center's y axis
     printf("New center point is %f %f\n",cx,cy);   //it display the new center
    
}

I need some ideas for solving this problem.im waiting for your helps :)

upps :D i forgot add a sample run
For example
we specified fir point (2,3)
and second point (4,5)
center point x=4+2/=3 ,y=3+5/2=4
and distance = sqrt(3^2+4^2)=5
and i will enter a new point such as (5,8)
at this time program have use (4,5) as a first point.thats to say
new center point is x=4+5/2=4.5 y=5+8/2=6.5
and new distance = sqrt(4.5^2+6.5^2)...something like that:D
i hope i've explained the question clearly :D

See this:
(y1+y2)/2

The answer to thins will be an integer, because y1 and y2 are integers and you're dividing by an integer. So if y1=0 and y2=3, the answer will not be 1.5

If you want non-integer answers, you have to turn the input into double or float.

Member Avatar for v3ga

--Your method for finding distance is wrong.
what u need to find is sqrt(pow((x2-x1),2)-pow((y2-y1),2))).
--In your do while loop, it should be while(x2!=0 && y2!=0)
--where is input Δ and output message?
--Also, the problem says "the center point of the points" not just the mid pt of the line segment joining 1st point and current point so i think u need to take centroid.

double findDelta(int x1,int x2,int y1,int y2)
{
     double result;
     int p1,p2;
     p1=pow((x2-x1),2);
     p2=pow((y2-y2),2);             // result is distance
     result=sqrt(p1+p2);
     printf("Distance=%f\n",result);       // it shows the distance 
}

The distance function is that but still somethings wrong.it doesnt show the result as a double like '2.5'.for example,i enter (3,4) and (2,3) the cehter should be (2.5,3,5) but program shows this (2,3).

Member Avatar for v3ga

U changed the distance function but the points are still int...
int calculations result in int so make all parameters float or double

I already said this once. Maybe you didn't read it. Here it is again.

See this:
(y1+y2)/2

The answer to this will be an integer, because y1 and y2 are integers and you're dividing by an integer. So if y1=0 and y2=3, the answer will not be 1.5

If you want non-integer answers, you have to turn the input into double or float.

The point is that if you divide an int by another int, you get back an int.

ok i got the idea.i'll change all parameters double.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double findDelta(double x1,double x2,double y1,double y2);  //function prototype for distance

double findNewCenter(double x1,double x2,double y1,double y2);  //function prototype for new center


int main(int argc, char *argv[])
{
  
  
  
  double distance; // the distance between two points
  double x1,x2,y1,y2;  // these are variables for dimensionals
  
  
  printf("Enter the x point\n");  // we specify first point
  scanf("%f",&x1);
  
  printf("Enter the y point\n");  // we specify second point
  scanf("%f",&y1);
  
                              
  do{
  printf("Enter another x point\n");  // getting new x point
  scanf("%f",&x2);
  
  printf("Enter another y point\n");   // getting new y point
  scanf("%f",&y2);
                           
 
  findNewCenter(x1,x2,y1,y2);          // function for finding new center
  findDelta(x1,x2,y1,y2);             // function for finding new distance
}while(x2!=0 && y2!=0);



  system("PAUSE");	
  return 0;
}


double findDelta(double x1,double x2,double y1,double y2)
{
     double result;
     double p1,p2;
     p1=pow((x2-x1),2);
     p2=pow((y2-y2),2);             // result is distance
     result=sqrt(p1+p2);
     printf("Distance=%f\n",result);       // it shows the distance 
}
double findNewCenter(double x1,double x2,double y1,double y2)
{
     double cx,cy;                            // center points' variables
     cx=(x1+x2)/2;                            // finding center's x axis
     cy=(y1+y2)/2;                            //  finding center's y axis
     printf("New center point is %.f,%.f \n",cx,cy);   //it display the new center
    
}

i changed the variables but still something wrong.Now the center point become 0,0 whatever i enter and also distance 0.
Screenshot>>http://imageshack.us/photo/my-images/85/123123123f.png/

In lines 20,23,28,31
The correct conversion specifier for doubles is %lf when using scanf

Member Avatar for v3ga

in line 50 its y2-y1
line 36 it should be while(x2!=0 || y2!=0) since u want it to end when it accepts (0,0) not when u input sth like (0,5) or (3,0) etc.
Also your functions are not void they should return value.
IMHO, Centre must mean the centre of all points as given in problem statement, so i think it should be (Σx/n,Σy/n).

in line 50 its y2-y1
line 36 it should be while(x2!=0 || y2!=0) since u want it to end when it accepts (0,0) not when u input sth like (0,5) or (3,0) etc.
Also your functions are not void they should return value.
IMHO, Centre must mean the centre of all points as given in problem statement, so i think it should be (Σx/n,Σy/n).

yes the center should be (Σx/n,Σy/n) but how can i do it?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double findDelta(double x1,double x2,double y1,double y2);  //function prototype for distance

double findNewCenter(double x1,double x2,double y1,double y2);  //function prototype for new center


int main(int argc, char *argv[])
{
  
  
  
  double distance; // the distance between two points
  double x1,x2,y1,y2;  // these are variables for dimensionals
  
  
  printf("Enter the x point\n");  // we specify first point
  scanf("%lf",&x1);
  
  printf("Enter the y point\n");  // we specify second point
  scanf("%lf",&y1);
  
                              
  do{
  printf("Enter another x point\n");  // getting new x point
  scanf("%lf",&x2);
  
  printf("Enter another y point\n");   // getting new y point
  scanf("%lf",&y2);
                           
 
  findNewCenter(x1,x2,y1,y2);          // function for finding new center
  findDelta(x1,x2,y1,y2);             // function for finding new distance
}while(x2!=0 && y2!=0);



  system("PAUSE");	
  return 0;
}


double findDelta(double x1,double x2,double y1,double y2)
{
     double result;
     double p1,p2;
     p1=pow((x2-x1),2);
     p2=pow((y2-y1),2);             // result is distance
     result=sqrt(p1+p2);
     printf("Distance=%.2lf\n",result);       // it shows the distance 
}
double findNewCenter(double x1,double x2,double y1,double y2)
{
     double cx,cy;                            // center points' variables
     cx=(x1+x2)/2;                            // finding center's x axis
     cy=(y1+y2)/2;                            //  finding center's y axis
     printf("New center point is %.4lf,%.4lf \n",cx,cy);   //it display the new center
    
}

Finally i solved the problems which are related the double variables.Now this program shows the exact values.Still some problems about center points.

Member Avatar for v3ga

Declare static variables count and sum in the function.
BTW, if u want only 0.4f, u can use float no need of double.

Declare static variables count and sum in the function.
BTW, if u want only 0.4f, u can use float no need of double.

im really grateful to all of you.i understood it in the end :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.