Thread: Need advice on how to fix

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    4

    Need advice on how to fix

    Ok so i am building a beginners program, to have a user input the center of a circle and then a point and find the radius, diameter, area, and circumference. I am suppose to use predefined functions and value returning functions. I put the error of what the compiler said on the line it had a problem with using comments please help if you can.

    Code:
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    using namespace std;
    
    double radius(double x, double y, double w, double z);
    double diameter(double x);
    double circumference(double x);
    double area(double x);
    const double p = 3.1416;
    
    int main()
    {
    	double orgin1, orgin2, pt1, pt2, radius, diameter, circumference;
    	
    	cout << setprecision(2) << fixed << showpoint;
    	
    	cout << "Please input the origin of your circle" << endl;
    	cin >> orgin1 >> orgin2;
    	cout << "Please input a point on the circle" << endl;
    	cin >> pt1 >> pt2;
    	cout << "Your origin is: " << "(" << orgin1 << "," << orgin2 << ")" << endl;
    	cout << "Your point is: " << "(" << pt1 << "," << pt2 << ")" << endl;
    	cout << "The radius of your circle is: " 
    		 << radius(pt1, orgin1, pt2, orgin2) << endl;// term doesn't evaluate 4arguements
    	cout << "The diameter of your circle is: " << diameter(radius) << endl;// term
    	cout << "The circumference of your circle is: "      // doesn't evaluate 1 arguement
    		 << circumference(diameter) << endl; // term doesn't evaluate 1 argument
    	cout << "The area of your circle is: " << area(radius) << endl;
    
    	return 0;
    }
    
    double radius(double x, double y, double w, double z)
    {
    	double radius, sum;
    
    	x = pow(x-y,2);
    	w = pow(w-z,2);
        sum = x + w;
    	radius = sqrt(sum);
    
    	return radius;
    }
    double diameter(double x)
    {
    	double diameter;
    	diameter = 2 * x;
    
    	return diameter;
    }
    double circumference(double x)
    {
    	double cicumference;
    	circumference = p * x;
    
    	return circumference; // cannot convert from double to double
    }
    double area(double x)
    {
    	double area;
    	x = pow(radius, 2); // none of the 7 overloads can convert parameter 1 from
    	area = p * x;       // type double
    
    	return area;
    }

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    The problem is your variables have the same names as your functions.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    some of the variables are kind-of unnecessary too, although there'd be nothing wrong with them if they had different names

    eg,
    Code:
    double circumference(double d) { return pi*d; }
    Also, you may find that your implementation already has "pi" defined as a constant somewhere.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Need advice about list of lists
    By handytxg in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2009, 05:03 PM
  3. Advice on C Programming with MSVC++ 2008
    By IT_Guy in forum Windows Programming
    Replies: 1
    Last Post: 03-06-2009, 04:23 AM
  4. C++ code need help to fix
    By McReal in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2007, 02:48 PM
  5. girl friend advice (prob. the wrong place)
    By B0bDole in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2004, 06:38 PM