這是一個非常基本的問題,我需要找到一個球體的面積和體積,但我收到此錯誤:錯誤C2065:未聲明的標識符
error C2065: 'v' : undeclared identifier
error C2065: 'a' : undeclared identifier
這裏是我的程序:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int r;
int computeSphere(int r) {
double a,v;
a = 4*3.14* pow(r,2);
v = (4/3) * 3.14 * pow(r,3);
return a,v;
}
int main() {
cout << "Enter the radius: ";
cin >> r;
cout << fixed << setprecision(2);
computeSphere(r);
cout << "The area of a sphere of radius " << r << " is " << a << " and its ";
cout << "volume is ";
cout << v;
cout << endl;
return 0;
}
問題說該函數不應該執行任何I/O操作。 那麼我該如何顯示結果?
這不是功能是如何工作的。檢查你在課堂上學到的內容,弄清楚你應該做什麼。 (你可以用指針,引用,結構體,類,宏或其他東西來做到這一點) – SLaks
「返回a,v;」和「4/3」都不會做你認爲他們做的事。閱讀一本好書,並在再次介紹一些C++基礎知識時再試一次。 –
可能重複[什麼是'未聲明的標識符'錯誤,以及如何解決它?](http://stackoverflow.com/questions/22197030/what-is-an-undeclared-identifier-error-and-how- do-i-fix-it) – sashoalm