adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
        double Op1 = 10, Op2 = 5, Res;
        char Op;
        try 
        {   
            if (Op != '+' && Op != '-' && Op != '*' && Op != '/')
                throw Op;
            switch(Op)
            {
            case '+':
                Res = Op1 + Op2;
                break;
            case '-':
                Res = Op1 - Op2;
                break;
            case '*':
                Res = Op1 * Op2;
                break;
            case '/':
                Res = Op1 / Op2;
                break;
             }
             cout << "\n" << Op1 << " " << Op << " "<< Op2 << " = " << Res;
         }
         catch (const char n)
         {
             cout << n << " is not a valid operator";
         }
         return 0;
    }

a.

15

b.

5

c.

2

d.

is not a valid operator

Answer: (d).is not a valid operator

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?