0
該地區始終輸出「0」。我無法計算出如何在int r
中計算面積。這個代碼爲什麼不輸出所需的輸出?
// Define a class and use it to test out some math stuff
#include <iostream>
#include <cmath>
using namespace std;
class Circle {
public:
// function that calculates the area of a circle
float circle_area(int r) {
area = 3.14 * (r*r);
return area;
} // end function circle_area
void display_msg() {
cout << "Area: " << circle_area(r) << endl;
} // end function display_msg
private:
float area;
int r;
}; // end class Circle
int main(void) {
int r;
Circle circle_calc; // create a Circle object named circle_calc
cout << "Radius of circle: ";
cin >> r;
circle_calc.display_msg();
}
'r'在主要是從類成員變量不同'r' – Mahesh 2012-01-12 21:20:07