Thread: I don't know how to do it!

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    13

    Question I don't know how to do it!

    please help... I dont know how to that

    in this code I try to perform number of commands;

    first getting tow points from the user.one represent the center of a circle and the other represent a point on the same circle.
    then I must use 4 functions . and then to print on the screen these solutions:
    r=radius d=diameter , c=circumference a= area. t
    I have many bugs but I have no clue how to solve it , thanks for the helpers.

    Code:
    double distance(double x1, double x2, double y1, double y2)
    {
    	double a=0 ,b=0 ,c=0, d=0 ,e=0 ;
    	a= x2 -x1;
    	b= y2 -y1;
    	c = a*a;
    	d = b*b;
    
    	e=c+d;
    
    	
    
    	return sqrt(e);
    
    
    }
    
    double radius(double r_x1, double r_y1, double r_x2, double r_y2)
    {
    	double  r =0;
    
    	r = distance(r_x1, r_x2, r_y1, r_y2);
    
    return r;
    }
    
    
    double circumference(double r)
    
    {
    	double  pai=3.1416, circ=0;
    
    	r = distance;
    	circ = rad * pai * 2;
    
    	return circ;
    }
    
    double area(double r)
    
    {
    	double rad = distance, pai =3.1416, c=0;
    
    
    	r = rad*rad*pai;
    
    	return r;
    }
    
    int main()
    
    {
    	 double x1=0, x2=0, y1=0, y2=0, D=0;
    
    	 printf("please enter tow points:\n");
    	 scanf("%g %g %g %g", &x1, &y1, &x2,&y2);
    
    	 D = distance(x1,x2,y1,y2) * 2;
    
    printf("R = %g \n ",distance(x1,x2,y1,y2));
    printf("D = %g \n" , 2* distance(x1,x2,y1,y2));
    printf("C = %g \n ",circ(r));
    printf("A = %g \n", area r));
    
    
    	return 0;
    
    }

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    46
    printf("C = %g \n ",circ(r));
    printf("A = %g \n", area r));
    variable r is not declared, so you should declare it first, before using or passing to any method(function).

    double area(double r)

    {
    double rad = distance, pai =3.1416, c=0;
    ....
    there is no variable called distance, you have a method called distance, so you cannot assign the variable the method name. you should call it with passing some arguements.


    These are two basic errors you get.... fix them, and ur done

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    13
    thank u for the help but, I didn't understand accuratly what to do.....
    I will be glad if u could to elaborate your solution.

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by sing0 View Post

    Code:
    #include<stdio.h>
    #include<math.h>
    double distance(double x1, double x2, double y1, double y2)
    {
    	double a=0 ,b=0 ,c=0, d=0 ,e=0 ;
    	a= x2 -x1;
    	b= y2 -y1;
    	c = a*a;
    	d = b*b;
    
    	e=c+d;
    
    	
    
    	return sqrt(e);
    
    
    }
    
    double radius(double r_x1, double r_y1, double r_x2, double r_y2)
    {
    	double  r =0;
    
    	r = distance(r_x1, r_x2, r_y1, r_y2);
    
    return r;
    }
    
    
    double circumference(double r)
    
    {
    	double  pai=3.1416, circ=0;
    
    	r = distance; // distance is a function, so you should call it like you have done in radius function	
    circ = rad * pai * 2; // declare rad variable in this function
    
    	return circ;
    }
    
    double area(double r)
    
    {
    	double rad = distance/*incorrect calling*/,pai =3.1416, c=0;
    
    
    	r = rad*rad*pai; //again rad
    
    	return r;
    }
    
    int main()
    
    {
    	 double x1=0, x2=0, y1=0, y2=0, D=0;
    
    	 printf("please enter tow points:\n");
    	 scanf("%g %g %g %g", &x1, &y1, &x2,&y2);
    
    	 D = distance(x1,x2,y1,y2) * 2;
    
    printf("R = %g \n ",distance(x1,x2,y1,y2));
    printf("D = %g \n" , 2* distance(x1,x2,y1,y2));
    printf("C = %g \n ",circ(r)); // declare r variable
    printf("A = %g \n", area (r));
    
    
    	return 0;
    
    }
    I've pointed out the errors. Remove them.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed