很简单的一段代码,各位老大帮俺查查错,谢谢

z33 2003-01-15 12:14:58
#include <iostream.h>
#include "shape.h"

void main()
{
int i,a,b,c;
while(1)
{
cout<<"1 圆"<<endl;
cout<<"2 矩"<<endl;
cout<<"3 方"<<endl;
cout<<"4 角"<<endl;
cout<<"5 平"<<endl;
cout<<"请选择:";
cin>>i;
while(i<1||i>5)
{
cout<<"错误,重新选择(1-5):";
cin>>i;
}
cout<<endl;
switch(i)
{
case 1:
cout<<"半径:";
cin>>a;
Round ro(a);
cout<<endl;
cout<<"圆的半径为 "<<ro.Getr()<<endl;
cout<<"圆的周长为 "<<ro.Getzou()<<endl;
cout<<"圆的面积为 "<<ro.Getmain()<<endl;
cout<<ro.Getname()<<endl;
break;
case 2:
cout<<"长,宽:";
cin>>a,b;
Reg re(a,b);
cout<<"矩形的长为 "<<re.Getchang()<<endl;
cout<<"矩形的宽为 "<<re.Getkuan()<<endl;
cout<<"矩形的周长为 "<<re.Getzuo()<<endl;
cout<<"矩形的面积为 "<<re.Getmain()<<endl;
break;
case 3:
cout<<"边:";
cin>>a;
Square sq(a);
cout<<"正方的长为 "<<sq.Getchang()<<endl;
cout<<"正方的周长为 "<<sq.Getzuo()<<endl;
cout<<"正方的面积为 "<<sq.Getmain()<<endl;
break;
case 4:
cout<<"边一,边二,边三:";
cin>>a,b,c;
Tri tr(a,b,c);
cout<<"三角形周长:"<<tr.Getzou()<<endl;
cout<<"三角形面积:"<<tr.Getmain()<<endl;
break;
case 5:
cout<<"底,斜,高:";
cin>>a,b,c;
Ping pi(3,5,4);
cout<<"平形四边形周长:"<<pi.Getzou()<<endl;
cout<<"平形四边形面积:"<<pi.Getmain()<<endl;
}
}
}



错误如下:
--------------------Configuration: shape - Win32 Debug--------------------
Compiling...
cMain.cpp
L:\cpp_shape\maker\cMain.cpp(34) : error C2360: initialization of 'ro' is skipped by 'case' label
L:\cpp_shape\maker\cMain.cpp(27) : see declaration of 'ro'
L:\cpp_shape\maker\cMain.cpp(43) : error C2360: initialization of 're' is skipped by 'case' label
L:\cpp_shape\maker\cMain.cpp(37) : see declaration of 're'
L:\cpp_shape\maker\cMain.cpp(43) : error C2360: initialization of 'ro' is skipped by 'case' label
L:\cpp_shape\maker\cMain.cpp(27) : see declaration of 'ro'
L:\cpp_shape\maker\cMain.cpp(51) : error C2360: initialization of 'sq' is skipped by 'case' label
L:\cpp_shape\maker\cMain.cpp(46) : see declaration of 'sq'
L:\cpp_shape\maker\cMain.cpp(51) : error C2360: initialization of 're' is skipped by 'case' label
L:\cpp_shape\maker\cMain.cpp(37) : see declaration of 're'
L:\cpp_shape\maker\cMain.cpp(51) : error C2360: initialization of 'ro' is skipped by 'case' label
L:\cpp_shape\maker\cMain.cpp(27) : see declaration of 'ro'
L:\cpp_shape\maker\cMain.cpp(58) : error C2360: initialization of 'tr' is skipped by 'case' label
L:\cpp_shape\maker\cMain.cpp(54) : see declaration of 'tr'
L:\cpp_shape\maker\cMain.cpp(58) : error C2360: initialization of 'sq' is skipped by 'case' label
L:\cpp_shape\maker\cMain.cpp(46) : see declaration of 'sq'
L:\cpp_shape\maker\cMain.cpp(58) : error C2360: initialization of 're' is skipped by 'case' label
L:\cpp_shape\maker\cMain.cpp(37) : see declaration of 're'
L:\cpp_shape\maker\cMain.cpp(58) : error C2360: initialization of 'ro' is skipped by 'case' label
L:\cpp_shape\maker\cMain.cpp(27) : see declaration of 'ro'
Error executing cl.exe.

shape.exe - 10 error(s), 0 warning(s)

...全文
41 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gull1234 2003-01-15
  • 打赏
  • 举报
回复
Round ro(a);
switch(i)
{
case 1:
cout<<"半径:";
cin>>a;

cout<<endl;
cout<<"圆的半径为 "<<ro.Getr()<<endl;
cout<<"圆的周长为 "<<ro.Getzou()<<endl;
cout<<"圆的面积为 "<<ro.Getmain()<<endl;
cout<<ro.Getname()<<endl;
break;
}
gull1234 2003-01-15
  • 打赏
  • 举报
回复
把函數定義等
Round ro(a);
拿到case外。
case 5:

69,372

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧