错误在我的 C++ 程序中重复大小写值。虽然我什么都改变不了

Dev*_*ere -2 c++ case duplicates switch-statement

我试图编写一个程序来帮助我找到给定角度的三角函数值。下面是程序,

    #include<iostream>
#include<cmath>
using namespace std;

void convert(char type);

int main()
{
    char ch;


    cout<<"Enter what angle value u want to calculate: 'c' for cos, 's' for sine and 't' for tan: ",cin>>ch;

    convert(ch);

    return 0;
}

void convert(char type)
{
    float angle;
    double num;
    switch (type)
    {
        case 'C' || 'c':
            cout<<"Enter angle value to calculate cos equivalent: ",cin>>angle;
            num = cos(angle);
            break;
        case 's' || 'S':
            cout<<"Enter angle value to calculate sin equivalent: ",cin>>angle;
            num = sin(angle);
            break;
        case 'T' || 't':
            cout<<"Enter angle value to calculate tan equivalent: ",cin>>angle;
            num = tan(angle);
            break;
        default:
            cout<<"\n\nInvalid Character\n";
    }
}
Run Code Online (Sandbox Code Playgroud)

但是代码给了我错误

[错误] 重复大小写值

有人请帮助我理解此错误背后的逻辑以及此问题的替代解决方案。

问候,

joh*_*ohn 5

如果你真的不能改变任何东西,那么你就被卡住了,但正确的代码是

case 'C': case 'c':
Run Code Online (Sandbox Code Playgroud)

等等等等

你应该明白这||是一个具有精确含义的运算符,它与英语中的'or'的含义不同。所以

case 'C' || 'c':
Run Code Online (Sandbox Code Playgroud)

并不意味着“案例 C 或 c”。这意味着计算'C' || 'c'case 语句的值并使用该值。