有人可以帮我处理我的代码吗?当我输入不在 if 语句中的数据时,我的 else 语句没有显示 [关闭]

问题描述 投票:0回答:0

如果我输入大于 5 或小于 1 的数字,我应该会收到一条声明说输入错误。但是,它只告诉我代码已完成,并且在我运行它时不会打印语句

if (choice >= 1 || choice <= 5)

{

switch (choice)
{
    {case 1:
        int result = a + b;
        cout << result << endl;
        break;}

    {case 2:
        int result = a - b;
        cout << result << endl;
        break; }

    {case 3:
        int result = a * b;
        cout << result << endl;
        break;}

    {case 4:

        double result = a / (double)b  ;
        cout << result<< endl;
        break;}

     {case 5:
        int result = a % b;
        cout <<  result << endl;
        break;}
       }
}
else
    {cout <<"Wrong entry" << endl;}

return 0;
}
c++ if-statement switch-statement
© www.soinside.com 2019 - 2024. All rights reserved.