wtmwf 2022-01-14 12:52 采纳率: 50%
浏览 221
已结题

C:\Users\86131\Desktop\c++\练习.cpp(23) : error C2143: syntax error : missing ';' before 'return'

#include<iostream>
using namespace std;
class Box
{
public:
    Box();
    Box(int w,int h,int l);
    Box(const Box &other);
    int V();
    int CV(Box other);
private:
    int width;
    int longth;
    int hight;
};
Box::Box():width(1),longth(1),hight(1){};
Box::Box(int l,int w,int h){width=w;longth=l;hight=h;}
Box::Box(const Box &other){width=other.width;longth=other.longth;hight=other.hight;}
int Box::V(){return width*longth*hight;}
int Box::CV(Box other){
    if(this->V()>other.V())return 1;
    else if(this->V()==other.V())return 0;
    else (this->V()<other.V())return -1;
}
int main(){
    Box s1;
    Box s2(2,8,6),s3(6,3,8);
    cout<<"s1体积为:"<<s1.V<<endl<<"s2体积为:"<<s2.V<<endl<<"s3体积为:"<<s3.V<<endl;
    if(s2.CV(s3)>0)cout<<"s2体积大于s3"<<endl;
    if(s2.CV(s3)==0)cout<<"s2体积等于s3"<<endl;
    if(s2.CV(s3)<0)cout<<"s2体积小于s3"<<endl;
    return 0;
}



运行结果及报错内容

C:\Users\86131\Desktop\c++\练习.cpp(23) : error C2143: syntax error : missing ';' before 'return'

我的解答思路和尝试过的方法
我想要达到的结果

我现在在计算体积和比较体积,但是提示我缺;但我没发现哪里缺;

  • 写回答

2条回答 默认 最新

  • 陆宇杭 2022-01-14 13:16
    关注

    23行,else后面加个if

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月22日
  • 已采纳回答 1月14日
  • 创建了问题 1月14日

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。