With this program I need to be able to find the circumference, area, diameter and radius of a circle. Here is what I have, please let me know of any advice you have:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
int main () 
{
    int x1;
    int x2;
    int y1;
    int y2;
    int dx;
    int dy;
    
    cout << "Enter the center point of the circle: " << endl;
    cin >> (x1, y1) >> (x2, y2);
    cout << "Enter a point on the circle" << endl;
    cin >> (x1, y1) >> (x2, y2);
    cout << endl;
    
int distance (x1, y1, x2, y2)
{
    dx = x2 - x1;
    dy = y2 - y1;
    float dsquared = dx * dx + dy * dy;
    float dresult = sqrt (dsquared);
    cout << "The distance of the circle is: " << dresult << " " << endl;
}

int radius (x1, y1, x2, y2)
{
    float radius = distance
    float dresult = area (radius);
    cout << "The radius of the circle is: " << dresult << " " << endl;
}

int circumference (float radius)
{
    float circumference = 3.1416 * (radius * 2);
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
int area (float radius)
{
    float area = (radius * radius) * 3.1416;
    cout << "The area of a circle is: " << area << " " << endl;
    cout << ' ' << endl;

    system ("pause");

    return 0;
}

I changed how I am writing it entirely. Please take a look at this one instead

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
int main () 
{
    float x1, x2, y1, y2;
    float dx, dy;
    float distance, circumference, area, radius;
    float dresult, dsquared;
    

    
    cout << "Enter the center point of the circle: ";
    cin >> (x1, y1);
    cout << "Enter a point on the circle: ";
    cin >> (x2, y2);
    cout << endl;
    
    distance = sqrt ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1));
    cout << "The distance between the two points on the circle is: " << distance << " " << endl;

   radius = distance;
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    circumference = 3.1416 * (radius * 2);
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    area = (radius * radius) * 3.1416;
    cout << "The area of a circle is: " << area << " " << endl;
    cout << ' ' << endl;

    system ("pause");

    return 0;
}

It looks mostly fine to me. I am still learning C++ but based on the complexity of your program, I think I am slightly more advance than you right now.

Does your code compile and run, giving the correct result? I am suspicious about your

cin

statements on lines 16 and 18. I have not seen any used with parentheses the way you have done. Still, your math is solid.

For more elegance, I would set up radius, circumference, and area as functions to call in the main section.

Nathaniel is right, you're using cin incorrectly. The correct syntax for getting multiple values with cin would be:

int x, y;
cout << "Type two numbers: ";
cin >> x >> y;

I would consider defining Pi as a global constant instead of using the "magic number" 3.1416. That way, you only have to define it once and you can't accidentally enter an incorrect value manually.

#include <iostream>
#include <iomanip>
#include <cmath>
 
const double PI = 3.1416;

using namespace std;
int main () {
  /* ... */
  double area = PI * (radius * radius);
  /* ... */
}

There are other, more precise, mathematical ways to define it as well, but this way should be sufficient.

Your math is sound, because of the "distributive" property of multiplication, but another thing I would consider, for clarity, is writing your statements/equations in the same order as the recognized formulas. For example, this:

circumference = 3.1416 * (radius * 2);

is mathematically sound under the distributive property, but initially it looks like the area formula area = Pi * r^2 when it is actually circumference = 2 * Pi * r

Edited 6 Years Ago by Fbody: n/a

Comments
Good point regarding PI as a constant.

Here is how I have it written now, and someone also stated "For more elegance, I would set up radius, circumference, and area as functions to call in the main section" I have read on this but am still slightly confused on how to do it. Is there anyway someone can give me an example or guide me a bit on how to do that? Thank you everyone for your time!

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;
int main () 
{

    float x1, x2, y1, y2;
    float distance, circumference, area, radius;

    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    distance = sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));

    cout << "The diameter of the circle is: " << distance << " " << endl;

   radius = distance;
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    circumference = 2 * pi * radius;
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    area = (radius * radius) * pi;
    cout << "The area of the circle is: " << area << " " << endl;
    cout << ' ' << endl;
    
    system ("pause");

    return 0;
}

Another thing that I was wondering is how would i put what I have in functions and not have it in main?

To take code out of main and put them in functions, start with what you have:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;
int main () 
{

    float x1, x2, y1, y2;
    float distance, circumference, area, radius;

    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    distance = sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));

    cout << "The diameter of the circle is: " << distance << " " << endl;

   radius = distance;
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    circumference = 2 * pi * radius;
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    area = (radius * radius) * pi;
    cout << "The area of the circle is: " << area << " " << endl;
    cout << ' ' << endl;
    
    system ("pause");

    return 0;
}

and turn it into this:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateCircumference(float radius);

int main () 
{

    float x1, x2, y1, y2;
    float distance, circumference, area, radius;

    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    distance = sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));

    cout << "The diameter of the circle is: " << distance << " " << endl;

   radius = distance;
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    circumference = CalculateCircumference(radius);
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    area = (radius * radius) * pi;
    cout << "The area of the circle is: " << area << " " << endl;
    cout << ' ' << endl;
    
    system ("pause");

    return 0;
}


float CalculateCircumference(float radius)
{
    return 2 * pi * radius;
}

All I did was take your circumference calculating code out of main and place it in a function called CalculateCircumference. Note the new function declaration at the top of the revised code and the function implementation at the bottom. The function call has changed from:

circumference = 2 * pi * radius;

to

circumference = CalculateCircumference(radius);

You can do the same with diameter, area, etc.

How do I fix what I did? I don't even really know what I did wrong.

//***************************************************************
// Author: Nancy Gutierrez
// Program number 6: Page 341
// CSC 160-C11
// Professor Terri Henderson
// October 24, 2010
// **************************************************************

// This program outputs the distance, radius, circumference and area of a circle
// based on the center point and point on the circle the user inputs.

//Header Declaration
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance (float x1, x2, y1, y2);

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    // Variable Declaration
    float x1, x2, y1, y2;
    float distance, circumference, area, radius;
    circumference = pi * radius * 2;

// Prompt the user to input the center point and one other point on the circle
    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    //Calculate the distance of the circle based on the formula provided
    CalculateDistance(float x1, x2, y1, y2);
    //output what the distance is
    cout << "The diameter of the circle is: " << distance << " " << endl;

// Radius and distance are going to be the same so set radius equal to distance
   CalculateRadius (float distance);
   //output what the radius is
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    //Calculate circumference using the formula 2 times pi times Radius
    circumference = CalculateCircumference(radius);
    //output what the circumference is
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    //Calculate radius using the formula radius squared multiplied by pi
    CalculateArea (float radius);
    //output what the area is
    cout << "The area of the circle is: " << area << " " << endl;
    //Extra line to make it easier to read.
    cout << ' ' << endl;
    
    //Required statement for viewing
    system ("pause");

    return 0;
} 

float CalculateDistance(float x1, x2, y1, y2)
{
      distance = sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
}

float CalculateRadius (float distance)
{
      radius = distance
}

float CalculateCircumference (float radius)
{
    return 2 * pi * radius;
}

float CalculateArea (float radius)
{
      area = (radius * radius) * pi
}

I've modified further to get

//***************************************************************
// Author: Nancy Gutierrez
// Program number 6: Page 341
// CSC 160-C11
// Professor Terri Henderson
// October 24, 2010
// **************************************************************

// This program outputs the distance, radius, circumference and area of a circle
// based on the center point and point on the circle the user inputs.

//Header Declaration
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance;

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    // Variable Declaration
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;
    circumference = pi * radius * 2;

// Prompt the user to input the center point and one other point on the circle
    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    //Calculate the distance of the circle based on the formula provided
    float CalculateDistance;
    //output what the distance is
    cout << "The diameter of the circle is: " << distance << " " << endl;

// Radius and distance are going to be the same so set radius equal to distance
   float CalculateRadius (float distance);
   //output what the radius is
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    //Calculate circumference using the formula 2 times pi times Radius
    float CalculateCircumference (float radius);
    //output what the circumference is
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    //Calculate radius using the formula radius squared multiplied by pi
    float CalculateArea (float radius);
    //output what the area is
    cout << "The area of the circle is: " << area << " " << endl;
    //Extra line to make it easier to read.
    cout << ' ' << endl;
    
    //Required statement for viewing
    system ("pause");

    return 0;
} 

float CalculateDistance(float x1, x2, y1, y2)
{
      return sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
}

float CalculateRadius (float distance)
{
      return distance
}

float CalculateCircumference (float radius)
{
    return 2 * pi * radius
}

float CalculateArea (float radius)
{
      return (radius * radius) * pi
}

How do I fix what I did? I don't even really know what I did wrong.

That depends completely on what seems to be wrong now. Care to elaborate?

float CalculateDistance(float x1, x2, y1, y2)
{
      distance = sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
}

float CalculateRadius (float distance)
{
      radius = distance
}

float CalculateCircumference (float radius)
{
    return 2 * pi * radius;
}

float CalculateArea (float radius)
{
      area = (radius * radius) * pi
}

One, remember to always put a semicolon after every executable statement. You forgot that in your functions.

Two, you need the key word "return" in there, so change this:

float CalculateArea (float radius)
{
      area = (radius * radius) * pi
}

to this:

float CalculateArea (float radius)
{
      return (radius * radius) * pi;
}

Or if you want, you can have this:

float CalculateArea (float radius)
{
      float area = (radius * radius) * pi;
      return area;
}

As far as calling the functions from main, you have this:

CalculateArea (float radius);

Get the word "float" out of there. That goes in the function declaration and the function itself, but not the function call.

This is better:

CalculateArea (radius);

But it's still missing one thing:

area = CalculateArea (radius);

You want to assign the return value of the function to a variable. In this case, the variable is area.

well to begin with line 73 x2 hasn't been declared, y1 is not a type, y2 has not been declared, ISO c ++ forbids declaration of 'parameter' with no type

>> That depends completely on what seems to be wrong now. Care to elaborate?

Good point, Walt. To the OP, always explain what the problem is. Often it'll help you solve it, plus it helps everyone else.

I'm still having some issues but have corrected some more issues

//***************************************************************
// Author: Nancy Gutierrez
// Program number 6: Page 341
// CSC 160-C11
// Professor Terri Henderson
// October 24, 2010
// **************************************************************

// This program outputs the distance, radius, circumference and area of a circle
// based on the center point and point on the circle the user inputs.

//Header Declaration
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance;

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    // Variable Declaration
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;
    circumference = pi * radius * 2;

// Prompt the user to input the center point and one other point on the circle
    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    //Calculate the distance of the circle based on the formula provided
    float CalculateDistance;
    //output what the distance is
    cout << "The diameter of the circle is: " << distance << " " << endl;

// Radius and distance are going to be the same so set radius equal to distance
   float CalculateRadius (float distance);
   //output what the radius is
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    //Calculate circumference using the formula 2 times pi times Radius
    float CalculateCircumference (float radius);
    //output what the circumference is
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    //Calculate radius using the formula radius squared multiplied by pi
    float CalculateArea (float radius);
    //output what the area is
    cout << "The area of the circle is: " << area << " " << endl;
    //Extra line to make it easier to read.
    cout << ' ' << endl;
    
    //Required statement for viewing
    system ("pause");

    return 0;
} 

float CalculateDistance(x1, x2, y1, y2);
{
      return sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
}

float CalculateRadius (distance);
{
      return distance
}

float CalculateCircumference (radius);
{
    return 2 * pi * radius
}

float CalculateArea (radius);
{
      return (radius * radius) * pi
}

This last program looks pretty good. You have a logic error that stems from your decision to use this intermediary variable you call 'distance'. You should realize that 'distance' and radius' are the same thing in your program because the distance you are calculating on line 75, from the circle center to its edge, IS the radius.

1) I would rename the CalculateDistance() function as CalculateRadius() and delete what you currently have as CalculateRadiius().

2) The diameter of your circle, on line 48, needs to be the 'distance' (now 'radius') times 2.

3) Because you are using variables 'radius', 'circumference', and 'area' in your cout statements, your functions need to return those variables. So the function for the radius should be

float CalculateRadius(float x1, x2, y1, y2)  {
   radius = sqrt[(x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)];
   return radius;
}

Are you running these versions of your program? I can't see you getting the correct output from your last program if you had run it.

EDIT: You have placed the functions BELOW the lines in which you use their return values. I am not sure on this point, but I suspect that the value of a variable, say radius, needs to be determined BEFORE you use it in an equation or cout command. In your variable declaration lines, you haven't initialized them to any particular values such as 0.0. So line 48 should yield an error because you are trying to use the variable 'distance' without it having any value.

I would put your function definitions just below your function declarations.

Edited 6 Years Ago by Nathaniel10: Second thought

//***************************************************************
// Author: Nancy Gutierrez
// Program number 6: Page 341
// CSC 160-C11
// Professor Terri Henderson
// October 24, 2010
// **************************************************************

// This program outputs the distance, radius, circumference and area of a circle
// based on the center point and point on the circle the user inputs.

//Header Declaration
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance;

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    // Variable Declaration
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;
    circumference = pi * radius * 2;

// Prompt the user to input the center point and one other point on the circle
    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    //Calculate the distance of the circle based on the formula provided
    float CalculateDistance;
    //output what the distance is
    cout << "The diameter of the circle is: " << distance << " " << endl;

// Radius and distance are going to be the same so set radius equal to distance
   float CalculateRadius (float distance);
   //output what the radius is
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    //Calculate circumference using the formula 2 times pi times Radius
    float CalculateCircumference (float radius);
    //output what the circumference is
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    //Calculate radius using the formula radius squared multiplied by pi
    float CalculateArea (float radius);
    //output what the area is
    cout << "The area of the circle is: " << area << " " << endl;
    //Extra line to make it easier to read.
    cout << ' ' << endl;
    
    //Required statement for viewing
    system ("pause");

    return 0;
} 

float CalculateDistance(x1, x2, y1, y2);
{
      return sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
}

float CalculateRadius (distance);
{
      return distance
}

float CalculateCircumference (radius);
{
    return 2 * pi * radius
}

float CalculateArea (radius);
{
      return (radius * radius) * pi
}

Re-read my last posts. Most of those same errors are there. There are three elements to this task:

  1. Function declaration. This will include the word float and a semicolon.
  2. Function call. This won't include the word float and a semicolon.
  3. Function. This will include the word float, but no semicolon.

#1 goes before main.
#2 goes inside main.
#3 goes after main.

Again, every executable line ends with a semicolon, so put them at the end of lines 75, 80, 85, and 90.

Line 21 isn't a function declaration. Make it look like lines 23, 25, and 27.

Delete line 36. You're replacing this later with a function call.

Line 56 - go back and look at my original example and remember rule 2 above. Get rid of the word float. It's this:

circumference = CalculateCircumference(distance);

Lines 73, 78, 83, 88 - again, look at my earlier example.

Line 83 should match line 23 except that you leave off the semicolon in line 83:

float CalculateCircumference (float radius)

The above is correct. float is in the front because that's the return type. float is inside the parentheses because that's the parameter type.

The CalculateDistance function takes four parameters, so it's going to be this:

float CalculateDistance(float x1, float y1, float x2, float y2);

Why bother with distance at all though if it's just the radius?

3) Because you are using variables 'radius', 'circumference', and 'area' in your cout statements, your functions need to return those variables. So the function for the radius should be

float CalculateRadius(float x1, x2, y1, y2)  {
   radius = sqrt[(x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)];
   return radius;
}

There's an error in line 1 here. It needs to be this:

float CalculateRadius(float x1, float x2, float y1, float y2)  {

Every parameter has a type. In this case, it's float. There are four parameters, so they all need the word float in front of them.

Also there are errors in line 2:

radius = sqrt[(x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)];

It needs to be:

float radius = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));

Replace the brackets with parentheses. radius is NOT a global variable, but instead is a variable declared inside main, so if you use a variable in both main and inside of a function, you must declare it in both.

The following four functions are all identical:

float CalculateRadius(float x1, float x2, float y1, float y2)  {
   float radius = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
   return radius;
}
float CalculateRadius(float x1, float x2, float y1, float y2)  {
   float bob = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
   return bob;
}
float CalculateRadius(float x1, float x2, float y1, float y2)  {
   return sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
}
float CalculateRadius(float a1, float a2, float b1, float b2)  {
   return sqrt((a2 - a1)*(a2 - a1) + (b2 - b1)*(b2 - b1));
}

You are completely free to name the variables in your function differently from what you use in main, or not name the at all and just return a calculation.

EDIT: You have placed the functions BELOW the lines in which you use their return values. I am not sure on this point, but I suspect that the value of a variable, say radius, needs to be determined BEFORE you use it in an equation or cout command. In your variable declaration lines, you haven't initialized them to any particular values such as 0.0. So line 48 should yield an error because you are trying to use the variable 'distance' without it having any value.

I would put your function definitions just below your function declarations.

It doesn't matter where you place the functions. What matters is that you place the function CALLS AFTER the parameters (i.e. the values in the parentheses are initialized) and BEFORE the value you assign to the return value is used.

Thus don't call a function that uses radius BEFORE you have calculated radius and don't display the circumference before you have called the CalculateCircumference function.

There are three elements to this task:

  1. Function declaration. This will include the word float and a semicolon.
  2. Function call. This won't include the word float and a semicolon.
  3. Function. This will include the word float, but no semicolon.

Awkward grammar. Too late to edit. #2 should be this:

Function call. This won't include the word float, but will have a semicolon at the end.

I changed a bit but am slightly overwhelmed by how much I need to change.
here are some of the errors I have, I figure once I can solve those problems I can solve the rest, I have a ton more errors though:
25 too few arguments to function `float CalculateRadius(float, float, float, float)'
50 at this point in file
50 At global scope:
72 redefinition of `float CalculateDistance'
21 `float CalculateDistance' previously declared here
72 `x1' was not declared in this scope
72 `x2' was not declared in this scope
72 `y2' was not declared in this scope
73 expected `,' or `;' before '{' token
77 `float CalculateRadius' redeclared as different kind of symbol
25 previous declaration of `float CalculateRadius(float, float, float, float)'
77 declaration of `float CalculateRadius'
25 conflicts with previous declaration `float CalculateRadius(float, float, float, float)'
78 cannot resolve overloaded function `distance' based on conversion to type `float'

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance;

float CalculateCircumference (float radius);

float CalculateRadius (float x1, float x2, float y1, float y2);

float CalculateArea (float radius);

int main () 
{
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;

    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    distance = CalculateDistance;
    
    cout << "The distance of the circle is: " << distance << " " << endl;

   radius = CalculateRadius (distance);
   
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    circumference = CalculateCircumference (radius);
    
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    CalculateArea (radius);
    
    cout << "The area of the circle is: " << area << " " << endl;
    
    cout << ' ' << endl;
    
    
    system ("pause");

    return 0;
} 

float CalculateDistance(x1, x2, y1, y2)
{
      return sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
}

float CalculateRadius (distance)
{
      return distance
}

float CalculateCircumference (radius)
{
    return 2 * pi * radius
}

float CalculateArea (radius)
{
      return (radius * radius) * pi
}

Get distance out of there, both in functions and variables. Distance is meaningless. If distance is diameter, label it diameter and calculate it from the radius. If distance is radius, you already have a variable named radius and all distance is doing is getting you confused.

Everything gets calculated from the radius, so call CalculateRadius first. CalculateRadius takes four parameters: x1, x2, y1, y2, which you get from the user.

As mentioned before, you need semicolons after every line inside your functions(i.e. every line that is between the brackets.

Incorrect :

CalculateArea (radius);

Look at your other function calls.

circumference = CalculateCircumference (radius);

This one's right. Model your other function calls after this one.

Read my posts again carefully. You are still making the same mistakes:

float CalculateCircumference (radius)

radius is of type float, so stick the word float in there. You should have the exact same thing at the bottom AFTER main as you do at the top BEFORE main, minus the semicolon

Here's what you have at the top.

float CalculateCircumference (float radius);

Copy it verbatim and stick it where you have your function, then delete the semicolon.

float CalculateCircumference (float radius)
Comments
Definitely. The simpler the better.

The problem verbatim when describing radius states "radius: This function takes as its parameters four numbers that represent the center and a point on the circle, cals the function distance to find the radius of a circle and returns the circle's radius" So if anything it is radius I need to get rid of but I'm not sure if I need to get rid of it. Distance is the distance between any 2 points on the circle but in this case the user can only input the center and a point which will then output the same number for radius

I have gotten it down to one error. On line 73 it is saying invalid function declaration

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance;

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;


    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    
    distance = CalculateDistance;
    
    cout << "The distance of the circle is: " << distance << " " << endl;


   radius = CalculateRadius (distance);
   
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    
    circumference = CalculateCircumference (radius);
    
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    
    CalculateArea (radius);
    
    cout << "The area of the circle is: " << area << " " << endl;
    
    cout << ' ' << endl;
    
   
    system ("pause");

    return 0;
} 

float CalculateDistance
{
      return sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
}

float CalculateRadius (float distance)
{
      return distance;
}

float CalculateCircumference (float radius)
{
    return 2 * pi * radius;
}

float CalculateArea (float radius)
{
      return (radius * radius) * pi;
}

Edited 6 Years Ago by baconswife: n/a

Fine, keep both, but if CalculateDistance calculates the distance between two points, then you need to pass it two x values and two y values, so it should have four parameters. You had it earlier with CaclulateRadius.

float CalculateDistance(float x1, float y1, float x2, float y2);

not

float CalculateDistance;

Okay, I think I have fixed everything now. Will someone please look at this and tell me what they think? Will you also please look over my notes on the program as well as this algorithm: A. Declare the headers
B. Declare functions
C. Declare the variables
D. Set format of output to two decimal places
E. Request input from user
F. Calculate the distance between the points, radius, circumference and area using the function statements
G. Output the calculations

//Header Declaration
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
//Declare pi as a constant
const double pi = 3.1416;

//Declare Functions
float CalculateDistance (float x1, float x2, float y1, float y2);

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    // Variable Declaration
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;

//Set format of output to two decimal places
    cout << fixed << showpoint;
    cout << setprecision (2);

// Prompt the user to input the center point and one other point on the circle
    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    //Calculate the distance of the circle based on the formula provided
    distance = CalculateDistance (x1, x2, y1, y2);
    //output what the distance is
    cout << "The distance of the circle is: " << distance << " " << endl;

// Radius and distance are going to be the same so set radius equal to distance
   radius = CalculateRadius (distance);
   //output what the radius is
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    //Calculate circumference using the formula 2 times pi times Radius
    circumference = CalculateCircumference (radius);
    //output what the circumference is
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    //Calculate radius using the formula radius squared multiplied by pi
    area = CalculateArea (radius);
    //output what the area is
    cout << "The area of the circle is: " << area << " " << endl;
    //Extra line to make it easier to read.
    cout << ' ' << endl;
    
    //Required statement for viewing
    system ("pause");

    return 0;
} 

float CalculateDistance (float x1, float x2, float y1, float y2)
{
      return sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
}

float CalculateRadius (float distance)
{
      return distance;
}

float CalculateCircumference (float radius)
{
    return 2 * pi * radius;
}

float CalculateArea (float radius)
{
      return (radius * radius) * pi;
}

Rereading the problem changed everything, can anyone tell me why my diameter is coming out to 0?

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
const double pi = 3.1416;

float CalculateDiameter (float radius);

float CalculateCircumference (float radius);

float CalculateRadius (float x1, float x2, float y1, float y2);

float CalculateArea (float radius);

int main () 
{
    
    float x1; 
    float x2;
    float y1, y2;
    float diameter, circumference, area, radius;

    cout << fixed << showpoint;
    cout << setprecision (2);


    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
   
    diameter = CalculateDiameter (radius);
    cout << "The diameter of the circle is: " << diameter << " " << endl;


   radius = CalculateRadius (x1, x2, y1, y2);
   
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    
    circumference = CalculateCircumference (radius);
    
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    
    area = CalculateArea (radius);
    
    cout << "The area of the circle is: " << area << " " << endl;
    
    cout << ' ' << endl;
    
   
    system ("pause");

    return 0;
    
} 

float CalculateRadius (float x1, float x2, float y1, float y2)
{
      return sqrt (pow (x2 - x1, 2) + pow(y2 - y1, 2));
}

float CalculateDiameter (float radius)
{
      return radius * 2;
}

float CalculateCircumference (float radius)
{
    return 2 * pi * radius;
}

float CalculateArea (float radius)
{
      return pow(radius, 2) * pi;
}

Edited 6 Years Ago by baconswife: n/a

You can't calculate anything from the radius until you have a radius. You don't have a radius until you call the CalculateRadius function, so that function call needs to happen before anything that relies on an accurate radius.

The problem verbatim when describing radius states "radius: This function takes as its parameters four numbers that represent the center and a point on the circle, cals the function distance to find the radius of a circle and returns the circle's radius" So if anything it is radius I need to get rid of but I'm not sure if I need to get rid of it. Distance is the distance between any 2 points on the circle but in this case the user can only input the center and a point which will then output the same number for radius

Then what you need is something like this:

double radius = CalcDistance(x1, y1, x2, y2);

or maybe:

//function call
double radius = CalcRadius(x1, y1, x2, y2);


//function definition
double CalcRadius(double x1, double y1, double x2, double y2) {
  return CalcDistance(x1, y1, x2, y2);
}

Edited 6 Years Ago by Fbody: n/a

This article has been dead for over six months. Start a new discussion instead.