#include <iostream>;
using namespace std;
/* this one works out when the float of the pi & area are in the end, but when it's in the top it does not work? */
int main()
{
float a, b;
/* float pi = 3.14 ;
float area = (pi*b*b/4) * ((2*a-b) / (2*a+b)); if it's in here it doesn't work */
cout << "please inter number n";
cin >> a ;
cout << "please inter number n";
cin >> b ;
cout << "****n" ;
float pi = 3.14 ;
float area = (pi*b*b/4) * ((2*a-b) / (2*a+b));
cout << area << endl;
return 0;
}
区域的设置取决于表达式中使用的变量中当前的值。
如果表达式位于顶部,则a
和b
都未设置为您的输入值。相反,它们会有一些任意的值,这意味着你的区域也会有一些随意的值。在输入a
和b
之后使用表达式,这些值将是您输入的实际值。
如果您在计算后立即放置以下代码(在这两种情况下(,您可以更清楚地看到这一点:
std::cout << "DEBUG: a = " << a << ", b = " << b
<< ", pi = " << pi << ", area = " << area << 'n';