标题:帮忙看看这个小程序,修改一下错误。运行了好几次,就是不知道哪错了
只看楼主
幕幕
Rank: 2
等 级:论坛游民
帖 子:19
专家分:10
注 册:2012-12-11
结帖率:100%
已结贴  问题点数:20 回复次数:8 
帮忙看看这个小程序,修改一下错误。运行了好几次,就是不知道哪错了
#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;
           }
       }

搜索更多相关主题的帖子: include 长方形 正方形 
2013-03-15 22:10
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:0 
怎么个错误法?

我行我乐
我的博客:
http://blog.yuccn. net
2013-03-15 22:19
幕幕
Rank: 2
等 级:论坛游民
帖 子:19
专家分:10
注 册:2012-12-11
得分:0 
您运行一下看看,出现好多行提示,我也不懂……但错误提示就一个
2013-03-15 22:21
幕幕
Rank: 2
等 级:论坛游民
帖 子:19
专家分:10
注 册:2012-12-11
得分:0 
--------------------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)

这是错误结果
2013-03-15 22:31
starlee1987
Rank: 2
等 级:论坛游民
帖 子:3
专家分:20
注 册:2013-3-15
得分:20 
哥  你错了好多啊
程序代码:
#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 编辑 ]
2013-03-15 22:33
starlee1987
Rank: 2
等 级:论坛游民
帖 子:3
专家分:20
注 册:2013-3-15
得分:0 
回复 5楼 starlee1987
cout<<"";
每一句结束要加;
2013-03-15 22:37
幕幕
Rank: 2
等 级:论坛游民
帖 子:19
专家分:10
注 册:2012-12-11
得分:0 
哦哦,知道啦。。。谢拉
2013-03-15 22:44
邓士林
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:淮河河畔
等 级:贵宾
威 望:61
帖 子:2391
专家分:13384
注 册:2013-3-3
得分:0 
小错误要注意哦!

Maybe
2013-03-16 00:43
幕幕
Rank: 2
等 级:论坛游民
帖 子:19
专家分:10
注 册:2012-12-11
得分:0 
哦哦……知道啦
2013-03-16 18:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-400889-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.190162 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved