很简单的一段代码,各位老大帮俺查查错,谢谢
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)