Basic calculator

what is wrong in this code:
#include
using namespace std;
int main(){
char ch;
long long int a,b;
ch=cin.get();
cin>>a>>b;
while((ch!=β€˜x’)||(ch!=β€˜X’))
{
switch(ch)
{
case β€˜+’:cout<<a+b<<endl;
break;
case β€˜-’:cout<<a-b<<endl;
break;
case '’:cout<<ab<<endl;
break;
case β€˜/’:cout<<a/b<<endl;
break;
case β€˜%’:cout<<a%b<<endl;
break;
default:cout<<β€œInvalid operation. Try again.”<<endl;
}
ch=cin.get();
cin>>a>>b;

}
return 0;

}

Your Mistakes

  1. don’t use cin.get() because it take whitespaces also
    if input is *
    1
    2
    /
    4
    2
    first cin.get() will take * and then cin.get() takes the newline character β€˜\n’ which is present after *

  2. don’t take a and b after every ch
    you don’t have to take a and b if ch is x or any other invalid character

look at modified Code

Modified code

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.