一只导盲犬要多少钱:一个简单的C++程序困扰我好久啊

来源:百度文库 编辑:高校问答 时间:2024/04/29 03:36:04
#include<iostream>
using namespace std;
const flaot PI=3.1416;
void main()
{
int i,r,wild,chang,zhchang;
cout<<"please chose the tyse/n"<<"yuan:0,zheng:1,chang:2"<<endl;
cin>>i;
switch(i)
{
case 0:cout<<"please input the r"<<endl;
cin>>r;
cout<<endl;
cout<<"yuan de mian ji wei"<<endl;
cout<<PI*r*r<<endl;
break;
case 1:cout<<"please input the wild and chang"<<endl;
cin>>wild>>chang;
cout<<endl;
cout<<"chang fang xing de mian ji shi:"<<endl;
cout<<chang*wild<<endl;
break;
case 2:cout<<"please input de zhchang"<<endl;
cin>>zhchang;
cout<<endl;
cout<<"zheng fang xing de mian ji shi:"<<endl;
cout<<zhchang*zhchang<<endl;
break;
default:cout<<"wrong"<<endl;
}
}

编译失败:
-------------------Configuration: 0321 - Win32 Debug--------------------
Compiling...
0321.cpp
E:\xingc\0321.cpp(3) : error C2146: syntax error : missing ';' before identifier 'PI'
E:\xingc\0321.cpp(3) : error C2734: 'flaot' : const object must be initialized if not extern
E:\xingc\0321.cpp(3) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

0321.exe - 1 error(s), 0 warning(s)

我找不出出错原因啊 ,但愿高手帮帮我啊!谢谢!!

第三行改为
const float PI=3.1416;

楼上的,
#include<iostream>
using namespace std;
才是标准C++

问题楼上的已经找出来了,还有一点就是程序里,你要求第一排正方形输入1,长方形输入2,但是在SWITCH语句中好象搞反了吧^^
<<当然这个不是编译错误的原因= =|||

#include<iostream>
using namespace std;
const flaot PI=3.1416;

试着把 using namespace std; 去掉
flaot写错了,应该是float 最好改为double
把#include<iostream>改为#include<iostream.h>
PS:我用的是VC++