error C2296: '^' : illegal, left operand has type 'float' 哪里出问题了啊?应该怎么输出πr^2?
#include<iostream>#include<math.h>usingnamespacestd;constdoublep=3.1416;intmain(){cou...
#include<iostream>
#include<math.h>
using namespace std;
const double p=3.1416;
int main()
{
cout<<"请选择图形1圆 2长方形 3正方形"<<endl;
float r,a,b,c;
int A;
cin>>A;
switch(A)
{
case 1:
cout<<"请输入圆的半径"<<endl;
cin>>r;
cout<<"圆的面积为"<<p*(r^2)<<endl;
break;
case 2:
cout<<"请输入长方形的长a和宽b"<<endl;
cin>>a;
cin>>b;
cout<<"长方形的面积为"<<a*b<<endl;
break;
case 3:
cout<<"请输入正方形的边长c"<<endl;
cin>>c;
cout<<"正方形的面积为"<<c*c<<endl;
break;
}
system("pause");
return 0;
} 展开
#include<math.h>
using namespace std;
const double p=3.1416;
int main()
{
cout<<"请选择图形1圆 2长方形 3正方形"<<endl;
float r,a,b,c;
int A;
cin>>A;
switch(A)
{
case 1:
cout<<"请输入圆的半径"<<endl;
cin>>r;
cout<<"圆的面积为"<<p*(r^2)<<endl;
break;
case 2:
cout<<"请输入长方形的长a和宽b"<<endl;
cin>>a;
cin>>b;
cout<<"长方形的面积为"<<a*b<<endl;
break;
case 3:
cout<<"请输入正方形的边长c"<<endl;
cin>>c;
cout<<"正方形的面积为"<<c*c<<endl;
break;
}
system("pause");
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询