Thread: Help Please

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

    Help Please

    The program pops up but then i get an error saying y2 is being used without being initialized. But i can't find it. If you find any other errors please tell me.

    Code:
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    using namespace std;
    
    double distance(double x1, double y1, double x2, double y2);
    double radius(double x1, double y1, double x2, double y2);
    double diameter(double rad);
    double circumference(double rad);
    double area(double rad);
    const double Pi = 3.1416;
    
    int main()
    {
    	double origin1, origin2, pt1, pt2, x1, x2, y1, y2, rad;
    	rad = (x1,y1,x2,y2);
    	cout << setprecision(2) << fixed << showpoint;
    	
    	cout << "Please input the origin of your circle" << endl;
    	cin >> origin1 >> origin2;
    	cout << "Please input a point on the circle" << endl;
    	cin >> pt1 >> pt2;
    	cout << "Your origin is: " << "(" << origin1 << "," << origin2 << ")" << endl;
    	cout << "Your point is: " << "(" << pt1 << "," << pt2 << ")" << endl;
    	cout << "The distance between the point and the origin is" 
    		 << distance(pt1, origin1, pt2, origin2) << endl;
    	cout << "The radius of your circle is: " 
    		 << radius(pt1, origin1, pt2, origin2) << endl;
    	cout << "The diameter of your circle is: " << diameter(rad) << endl;
    	cout << "The circumference of your circle is: "      
    		 << circumference(rad) << endl; 
    	cout << "The area of your circle is: " << area(rad) << endl;
    
    	return 0;
    }
    
    double distance(double x1, double y1, double x2, double y2)
    {
    	return sqrt(pow(x1-y1,2) + pow(x2-y2,2));
    }
    double radius(double x1, double y1, double x2, double y2)
    {
        return distance(x1, y1, x2, y2);
    }
    double diameter(double rad)
    {
    	return 2 * rad;
    }
    double circumference(double rad)
    {
    	return Pi * rad; 
    }
    double area(double rad)
    {
    	
    	return pow(rad, 2); 
    }

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Code:
    	double origin1, origin2, pt1, pt2, x1, x2, y1, y2, rad;
    	rad = (x1,y1,x2,y2); // eh??? what's this supposed to be?
    what are you trying to do there?
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    it should be someting like this:
    Code:
                   cin>>origin1>>origin2;
    	cin >> pt1 >> pt2;
                    rad=radius(pt1, origin1, pt2, origin2);

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    The program pops up but then i get an error saying y2 is being used without being initialized.
    Code:
    double origin1, origin2, pt1, pt2, x1, x2, y1, y2, rad; <====y2 not initialized
    
    rad = (x1,y1,x2,y2);<====y2 being used
    If you find any other errors please tell me.
    x1, x2, and y1 are being used without being initialized.

    Rule #1 in programming: "Always initialize your variables."
    Last edited by 7stud; 03-02-2006 at 01:00 AM.

Popular pages Recent additions subscribe to a feed