0
votes

I am still very new to C++ and programming in general, so be gentle.

Given the center and a point on the circle, you can use this formula to find the radius of the circle. Write a program that prompts the user to enter the center and a point on the circle. The program should then output the circle’s radius, diameter, circumference, and area. Your program must have at least the following functions:

calculateRadius: Receives the x-y coordinates of the center and point on the circle (as input by the user) and calculates the distance between the points. This value is returned as the radius of the circle.

calculateArea: Receives the radius of a circle, calculates and returns the area of the circle.

calculatePerimeter: Receives the radius of a circle, calculates and returns the perimeter of the circle.

The output should clearly display the radius, area, and perimeter of the resulting circle.

This is what I have so far and it is giving me numbers and letters as an output.

#include <iostream>
#include <cmath>
#define PI 3.141592

using namespace std;

int calculateRadius(float x1, float x2, float y1, float y2);
int calculateArea(float radius);
int calculatePerimeter(float radius);

int main()
{
    float x1;
    float x2;
    float y1;
    float y2;

    cout << "Please enter the first X Coordinate: " << endl;
    cin >> x1;
    cout << "Please enter the first Y Coordinate: " << endl;
    cin >> y1;

    cout << "Please enter the second X Coordinate: " << endl;
    cin >> x2;
    cout << "Please enter the second Y Coordinate: " << endl;
    cin >> y2;

    cout << "The radius of the circle is: " << calculateRadius << endl;
    cout << "The diameter of the circle is: " << endl;
    cout << "The cirfumference of the circle is: " << calculatePerimeter << endl;
    cout << "The area of the circle is: " << calculateArea << endl;

    system("pause");
    return 0;
}

int calculateRadius(float x1, float x2, float y1, float y2)
{
    float distance;
    float radius;

    distance = sqrt((pow(x2 - x1, 2)) + (pow(y2 - y1, 2)));

    radius = (distance / 2);

    return radius;
}

int calculateArea(float radius)
{
    float area;

    area = PI * pow(radius, 2);

    return area;
}

int calculatePerimeter(float radius)
{
    float perimeter;

    perimeter = 2 * PI * radius;

    return perimeter;
}
2
And what's your question? This is quite broad.Carcigenicate
@Carcigenicate When i run the code I am getting back numbers and letters which is obviously wrong. I don't know what I am doing wrong though. So my question is if someone could find the reason I am getting incorrect answers back.Jcarlton55
@Jcarlton55 If you have any update (like your comment), It is better, to edit your own question with clear information.timiTao

2 Answers

1
votes

You also need to change the return type of your functions from int to float since you are working with single precision.

0
votes

You need to specify the arguments for the function

#include <iostream>
#include <cmath>
#define PI 3.141592

using namespace std;

int calculateRadius(float x1, float x2, float y1, float y2);
int calculateArea(float radius);
int calculatePerimeter(float radius);

int main()
{
    float x1;
    float x2;
    float y1;
    float y2;

    cout << "Please enter the first X Coordinate: " << endl;
    cin >> x1;
    cout << "Please enter the first Y Coordinate: " << endl;
    cin >> y1;

    cout << "Please enter the second X Coordinate: " << endl;
    cin >> x2;
    cout << "Please enter the second Y Coordinate: " << endl;
    cin >> y2;

    cout << "The radius of the circle is: " << calculateRadius(x1,x2,y1,y2) << endl;
    cout << "The diameter of the circle is: " << endl;
    cout << "The cirfumference of the circle is: " << calculatePerimeter(x1) << endl;
    cout << "The area of the circle is: " << calculateArea(x1) << endl;

    system("pause");
    return 0;
}

int calculateRadius(float x1, float x2, float y1, float y2)
{
    float distance;
    float radius;

    distance = sqrt((pow(x2 - x1, 2)) + (pow(y2 - y1, 2)));

    radius = (distance / 2);

    return radius;
}

int calculateArea(float radius)
{
    float area;

    area = PI * pow(radius, 2);

    return area;
}

int calculatePerimeter(float radius)
{
    float perimeter;

    perimeter = 2 * PI * radius;

    return perimeter;
}