注册 登录
编程论坛 C++教室

帮忙看看这个小程序,修改一下错误。运行了好几次,就是不知道哪错了

幕幕 发布于 2013-03-15 22:10, 1647 次点击
#include <iostream>
using namespace std;

   const float PI=3.1416;
   float r,a,b,c,s;
       int main()
       {
           int i;
           cout<<"圆形1,长方形2,正方形3:";
           cin>>i;
           switch(i)
           {
           case 1:
               cout<<"圆形的半径为:"
               cin>>r;
               s=PI*r*r;
               cout<<"圆形的面积为:"<<s<<endl;
               break;
           case 2:
               cout<<长方形的长为:"
               cin>>a;
               cout<<长方形的宽为:"
               cin>>b;
               s=a*b;
               cout<<"长方形的面积为:"<<s<<endl;
               break;
           case 3:
               cout<<正方形的边长为:"
               cin>>c;
               s=c*c;
               cout<<"正方形的面积为:"<<s<<endl;
               break;
           default:
           cout<<s<<endl;
           }
       }

8 回复
#2
yuccn2013-03-15 22:19
怎么个错误法?
#3
幕幕2013-03-15 22:21
您运行一下看看,出现好多行提示,我也不懂……但错误提示就一个
#4
幕幕2013-03-15 22:31
--------------------Configuration: sss - Win32 Debug--------------------
Compiling...
ssss.cpp
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\ssss.cpp(15) : error C2374: 'i' : redefinition; multiple initialization
        D:\Program Files\Microsoft Visual Studio\MyProjects\sss\ssss.cpp(9) : see declaration of 'i'
xghj.cpp
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(4) : warning C4305: 'initializing' : truncation from 'const double' to 'const float'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(15) : error C2146: syntax error : missing ';' before identifier 'cin'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xb3'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xa4'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xb7'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xbd'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xd0'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xce'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xb5'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xc4'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xb3'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xa4'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xce'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2018: unknown character '0xaa'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2059: syntax error : ':'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(20) : error C2001: newline in constant
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xb3'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xa4'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xb7'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xbd'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xd0'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xce'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xb5'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xc4'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xbf'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xed'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xce'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2018: unknown character '0xaa'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2059: syntax error : ':'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(22) : error C2001: newline in constant
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xd5'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xfd'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xb7'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xbd'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xd0'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xce'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xb5'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xc4'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xb1'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xdf'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xb3'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xa4'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xce'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2018: unknown character '0xaa'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2059: syntax error : ':'
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(28) : error C2001: newline in constant
D:\Program Files\Microsoft Visual Studio\MyProjects\sss\xghj.cpp(36) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.

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

这是错误结果
#5
starlee19872013-03-15 22:33
哥  你错了好多啊
程序代码:
#include <iostream>

 using namespace std;

        const double PI=3.1416;
            float r,a,b,c,s;
        int main()
        {
            int i;
            cout<<"圆形1,长方形2,正方形3:";
            cin>>i;
            switch(i)
            {
            case 1:
                cout<<"圆形1,长方形2,正方形3:";
                cin>>r;
                s=PI*r*r;
                cout<<"圆形的面积为:"<<s<<endl;
                break;
            case 2:
                cout<<"长方形的长为:";
                cin>>a;
                cout<<"长方形的宽为:";
                cin>>b;
                s=a*b;
                cout<<"长方形的面积为:"<<s<<endl;
                break;
            case 3:
                cout<<"正方形的边长为:";
                cin>>c;
                s=c*c;
                cout<<"正方形的面积为:"<<s<<endl;
                break;
            default:
            cout<<s<<endl;
            }
            return 0;
        }

 


[ 本帖最后由 starlee1987 于 2013-3-15 22:36 编辑 ]
#6
starlee19872013-03-15 22:37
回复 5楼 starlee1987
cout<<"";
每一句结束要加;
#7
幕幕2013-03-15 22:44
哦哦,知道啦。。。谢拉
#8
邓士林2013-03-16 00:43
小错误要注意哦!
#9
幕幕2013-03-16 18:35
哦哦……知道啦
1