error in using switch case

73 views Asked by At

in the following code:

    switch(a)
    {

    case '+' :
        result=num1+num2;
    break;

    case '-' :
        result=num1-num2;
    break;

    case '*' :
        result=num1*num2;
    break;

    case '/' :
        result=num1/num2;
    break;

    case '^' :
        result=pow(num1,num2);
    break;

    default :
       cout << "Invalid operator" << endl;
    }

is the char pointer, and the error is: error: switch quantity not an integer...

1

There are 1 answers

2
Sergey Kalinichenko On BEST ANSWER

If a is a pointer, you cannot use it in the switch: you need to dereference it first - either like this

switch(*a)

or like this

switch(a[0])