#include<cmath> //因為用到了sqrt()函數,sqrt()為開根號
using namespace std;
int main()
{
cout<<"1計算圓面積"<<endl
<<"2計算矩形面積"<<endl
<<"3計算三角形面積"<<endl
<<"4退出"<<endl
<<"請選擇相應程序代碼:";
int x; //x對應編號
cin>>x;
double area;
while(x!=4) //當x!=4時循環,即當x=4時退出循環
{
if(x==1)
{
double r;
cout<<"半徑:";
cin>>r;
area=3.14*r*r;
cout<<"面積為 "<<area<<endl;
}
else if(x==2)
{
double a,b;
cout<<"長和寬:";
cin>>a>>b;
area=a*b;
cout<<"面積為 "<<area<<endl;
}
else if(x==3)
{
double a,b,c,d;
cout<<"三邊長:";
cin>>a>>b>>c;
d=0.5*(a+b+c);
area=sqrt(d*(d-a)*(d-b)*(d-c));
cout<<"面積為 "<<area<<endl;
}
else
cout<<"輸入有誤,請重新輸入!"<<endl;
cout<<"程序代碼:";
cin>>x;
}
return 0;
}