+ 1

Write a program to take + for addition , - for subtraction ,* for multiplication ,/ for division. & Give output according .

#include<iostream> using namespace std; void test (int a,int b ) { try { int c ,d,e,f,g; char p; c = a+b ; d = a-b; e = a*b ; f = a/b; g = a%b; cout<<" Enter + for addition ; - for subtraction ; * for multiplication , / for division ,% for modulas "; cin>>p; if (p == +) throw c ; else if (p == -) throw d ; else if (p == *) throw e ; else if (p == /) throw f; else if (p == %) throw g ; } catch (int c ){ cout<<" addtion of two number : "<<c<<endl; } catch (int d ){ cout << " subtraction of two number "<<d<<endl; } catch (int e ){ cout << " Multiplication of two number "<<e<<endl; } catch (int f ){ cout << " Division of two number "<<f<<endl; } int main () { cout<<"Multiple catches " <<endl; test (10,57); return 0 ;

15th Jan 2021, 9:09 AM
ROHIT KUMAR
ROHIT KUMAR - avatar
2 Réponses
+ 1
《 Nicko12 》 #include<iostream> using namespace std; int test (int a,int b ) { try { int c ,d,e,f,g; // char p; c = a+b ; d = a-b; e = a*b ; f = a/b; g = a%b; cout<<" Enter + for addition ; - for subtraction ; * for multiplication , / for division ,% for modulas "; char p ; cin>>p; if ('p' == '+') throw c ; else if ('p' == '-') throw d ; else if ('p' == '*') throw e ; else if ('p' == '/') throw f; else throw g ; } catch (int c ){ cout<<" addtion of two number : "<<c<<endl; } catch (int d ){ cout << " subtraction of two number "<<d<<endl; } catch (int e ){ cout << " Multiplication of two number "<<e<<endl; } catch (int f ){ cout << " Division of two number "<<f<<endl; } catch (int g ){ cout << " Modulas of two number "<<g<<endl;
15th Jan 2021, 9:37 AM
ROHIT KUMAR
ROHIT KUMAR - avatar
0
You are comparing char data-types here so the operators you are comparing with "p" must have quotation marks ( ' ): (e.g. '+') if (p == '+') ...
15th Jan 2021, 9:17 AM
noteve
noteve - avatar