我對C++和編程一般還很新,所以要溫和。C++ - 我得到的數字和字母的輸出有問題
給定中心和圓上的點,可以使用此公式找到圓的半徑。編寫一個程序,提示用戶輸入中心和圓上的一個點。程序應該輸出圓的半徑,直徑,圓周和麪積。您的程序必須至少具有以下功能:
calculateRadius:接收中心的x-y座標並指向圓(由用戶輸入)並計算點之間的距離。該值作爲圓的半徑返回。
calculateArea:接收一個圓的半徑,計算並返回該圓的面積。
calculatePerimeter:接收一個圓的半徑,計算並返回圓的周長。
輸出應清楚顯示所得圓的半徑,面積和周長。
這是我到目前爲止,它是給我數字和字母作爲輸出。
#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;
}
什麼是你的問題?這是相當廣泛的。 – Carcigenicate
@Carcigenicate當我運行代碼時,我得到的數字和字母顯然是錯誤的。我不知道我做錯了什麼。所以我的問題是,如果有人能找到我得到錯誤答案的原因。 – Jcarlton55
@ Jcarlton55如果您有任何更新(如您的評論),最好是用清晰的信息編輯您自己的問題。 – timiTao