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'へのアクセス権を持っているように、n'私はOPは、スコープの概念を理解していない疑いがある – Mahesh