我正在學習C++,我正在做這個練習,它使用函數打印三角形的區域,但是當我嘗試編譯「錯誤]「calcarea」未在此範圍內聲明「在C++上編譯錯誤,在此範圍內沒有聲明calcarea
#include<iostream>
#include<cstdlib>
using namespace std;
double farea;
main(){
float base, height;
cout<<"Enter base of triangle: "; cin>>base;
cout<<"Enter height of triangle: "; cin>>height;
cout<<endl;
farea = calcarea(base,height);
cout<<"The area of the triangle is: "<<farea;
system("pause>nul");
}
double calcarea(float ba, float he){
double area;
area = (ba*he)/2;
return area;
}
感謝有效! – OsmaK