这是我为一个项目创建的代码。它的基本的东西,但我一定是忽略了一些东西,因为当我运行它,无论我穿什么号码的radious它给了我同样的答案:C++程序错误结果
radious given:288
x=260444.
这是为什么?
#include <iostream>
#include <stdlib.h>
#include <math.h>
#define pi 3.14
using std::cout;
using std::cin;
using std::endl;
class Circle
{
private:
int Radious;
public:
bool setRadious(int R);
int getRadious(){return Radious;}
double getx();
};
bool Circle::setRadious(int R)
{
bool RadiousSet = false;
if (R > 0) //check validity of R
{
int Radious = R;
RadiousSet = true;
}
return RadiousSet;
}
//x = pi *R^2
double Circle::getx()
{
return pi*pow(Radious,2);
}
// -----------------------------
int main()
{
int R=0;
bool rslt;
Circle myCircle;
cout<<"Give Radious: ";
cin>>R;
rslt = myCircle.setRadious(R);
if(rslt == true)
{
cout << "Radious given: " <<myCircle.getRadious();
cout<<"x: "<<myCircle.getx()<<endl;
}
else
cout<<"Radious must be greater than zero"<<endl;
system("pause");
return 0;
}
它应该是半径不radious :) – Templar
是的,我知道,但教授写道它,我们不得不修改他的代码,使其工作.. :) – System