问题:我想编一个计算三角形等面积和周长的程序,代码如下:
提示错误为:fatal error C1083: Cannot open include file: 'math': No such file or directory
如果去掉#include <math>,则提示错误为:error C2143: syntax error : missing ';' before 'string'
我是个新手,求高手解释,感激不尽!
#include <iostream>
#include <math>
using namespace std;
int main()
{
int int_type,int_figure,int_all;
int_type=int_figure=int_all=0;
double a,b,c,s;
a=b=c=s=0;
do
{
cout<<"请选择您要计算的类型:\n";
cout<<"0.周长 1.面积\n";
cin>>int_type;
} while(int_type!=0||1);
do
{
cout<<"请选择您要计算的图形:\n";
cout<<"2.正三角形 4.正方形 5.矩形 6.圆\n";
cin>>int_figure;
} while(int_figure!=2||4||6||8);
int_all=int_type+int_figure;
cout<<"请输入边长或半径:\n";
cin>>a;
switch (int_all)
{
case 2:c=3*a;
break;
case 3:s=sqrt(3)*a/4;
break;
case 12:c=4*a;
break;
case 4:s=a*a;
break;
case 5:cout<<"请输入另一边长:\n";
cin>>b;
c=2*(a+b);
break;
case 6:cout<<"请输入另一边长:\n";
cin>>b;
s=a*b;
break;
case 7:c=2*3.1415926*a;
break;
case 8:s=3.1415926*a*a;
break;
default:cout"系统错误,请重试!\n";
}
cout<<"您要求的结果为:"<<(c+s)<<"\n";
return 0;
}
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
do
{
cout<<"请选择您要计算的类型:\n";//++++++++++++++++++++++++++++++++++++++++++++++++++++++
cout<<"0.周长 1.面积\n";
cin>>int_type;
}while(int_type!=0&&int_type!=1);
do
{
cout<<"请选择您要计算的图形:\n";
cout<<"2.正三角形 4.正方形 5.矩形 6.圆\n";
cin>>int_figure;
} while(int_figure!=2&&4&&5&&6);