小编Set*_*iba的帖子

计算器程序无法编译

我写了一个实现简单计算器的程序.但是,它没有编译.编译器说有22个错误,我不知道为什么.

期望的行为:

  1. 询问用户所需的操作
  2. 向用户询问参数
  3. 输出结果

具体问题或错误:

在任何发生编译错误cin,cout,endl,casebreak

最小,完整和可验证的示例:

#include <iostream>
int main()
{
    float area, r, l, h, b;
    int choice;
    cout<<"\n area of?";
    cout<<"\n[1]square \n[2]rectangle \n[3]circle \n[4]triangle"<<endl;
    cin>>choice;
    switch(choice);
    {
    case 1:
        cout<<"enter length"<<endl;
        cin>>l;
        area=l*l;
        cout<<area<<endl;
        break;
    case 2:
        cout<<"enter height"<<endl;
        cin>>h;
        cout<<"enter length"<<endl;
        cin>>l;
        area=l*h;
        cout<<area<<endl;
        break;
    case 3:
        cout<<"enter radius"<<endl;
        cin>>r;
        area=r*r*3.14;
        cout<<area<<endl;
        break;
    case 4:
        cout<<"enter height"<<endl;
        cin>>h;
        cout<<"enter breadth"<<endl;
        cin>>b;
        area=h*b*0.5;
        cout<<area<<endl;
        break;
    }

    return …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors switch-statement

-7
推荐指数
1
解决办法
79
查看次数

标签 统计

c++ ×1

compiler-errors ×1

switch-statement ×1