C ++ Проблемы с передачей функций (математика не складывается) - PullRequest
0 голосов
/ 21 ноября 2018

У меня есть задание на с ++, где я должен найти радиус, окружность и площадь круга.Я думаю Мне удалось правильно передать функции, но, возможно, нет, потому что программа отказывается отображать правильную площадь и окружность круга, несмотря на вызов радиуса в качестве параметра.Я вставляю свои формулы для окружности и площади, и программа выкладывает обратно полностью отключенные числа.в любом случае, вот мой код ниже, любая помощь будет так цениться.Спасибо

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

using namespace std;

//declare prototypes

float radius_of_circle(float x1, float y1, float x2, float y2);
float distance(float xxx1, float yyy1, float xxx2, float yyy2);
float circum(float distance);
float area(float area_of_circle);

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

    // prompt the user 

    cout << "Please enter the first X value below " << endl;
    cin >> x1;
    cout << "Now enter the first Y value below" << endl;
    cin >> y1;
    cout << "Please enter the second X value below " << endl;
    cin >> x2;
    cout << "Now enter the second Y value below " << endl;
    cin >> y2;
    cout << endl;
    cout << endl;

    //display the center and point of the circle

    cout << "The CENTER of the circle is...(" << x1 << " , " << y1 << ")" << endl;
    cout << endl;
    cout << "A POINT on the circle is...(" << x2 << " , " << y2 << ")" << endl;
    cout << endl;

    // create new function to call 

    float dist = distance(x1, y1, x2, y1);





    cout << " The Distance between the points is..." << radius_of_circle(x1, y1, x2, y2) << endl;
    cout << endl;
    cout << " The Radius of the Circle is..." << radius_of_circle(x1, y1, x2, y2) << endl;
    cout << endl;
    cout << " The Circumference of Circle is... " << circum(dist) << endl;
    cout << endl;
    cout << " The Area of Circle is... : " << area(dist) << endl;
    cout << endl;

    system("PAUSE");
    return 0;

}

//radius function

float distance (float xx1, float yy1, float xx2, float yy2) {

    int distancex = pow(xx2 - xx1, 2);
    int distancey = pow(yy2 - yy1, 2);
    return sqrt(distancex + distancey);
}


// distance function

float radius_of_circle(float xxx1, float yyy1, float xxx2, float yyy2) {
    return distance(xxx1, yyy1, xxx2, yyy2);

}


//circumference function

float circum(float distance)
{

    return 2 * 3.1416 * distance;
}

//area function

float area(float distance) {

    return 3.1416 * pow(distance, 2) ;
}

спасибо за такие быстрые ответы ... вот результат.по-видимому, радиус рассчитывается правильно, но площадь и окружность, а не.Благодарю.

выход

1 Ответ

0 голосов
/ 21 ноября 2018

Ваша ошибка здесь

float dist = distance(x1, y1, x2, y1);

обратите внимание на последний параметр.У вас есть y1 вместо y2

Код должен быть

float dist = distance(x1, y1, x2, y2);
...