How to use input operator

d= a β€˜ch’ b;
i cin>>ch;
now just want operation on and b

how tom write

hi @naaz, are you asking how to take input for this question ??

Well , what you can do is, you can use while loop and in every iteration take a character as input, say ch
if ch is β€˜x’ or β€˜X’ then break out of the loop else ,take two more integer input and perform the operation defined by ch, for this you can use switch(or if else conditions) that all it is to this question

refer this code for more clarity :-

In case of any doubt feel free to ask :slight_smile:

#include using namespace std; int main() { int a,b,d; char ch; cin>>ch; while(ch!=β€˜X’ || ch!=β€˜x’) { if(ch=’+’|| β€˜-’|| β€˜*’|| β€˜/’||’%’ ) { cin>>a>>b; d= a β€˜ch’ b; cout<<d; } else cout<<β€œInvalid operation. Try again.”; cin>>ch; } return 0; }

i have sent you my code what is mistake in that code

1 Like

d= a β€˜ch’ b is not a valid operation , let’s say ch is ’ * ’ then d=a ’ * ’ b is not a valid operation as * is a character not a operator instead d=a * b is a valid operation as * is an operator defined by c++
so you have to do something like :-

if(ch=='*'){
    d =a * b;
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.