I am getting TLE in my program of basic calculator i don't know why

#include
using namespace std;
int main()
{ char ch;
int n1 ,n2,ans;
do
{
cin>>ch;
if (ch==’+’ or ch==’-’ or ch==’’ or ch==’/’ or ch==’%’)
{
cin>>n1>>n2;
switch (ch){
case’+’:
ans=n1+n2;
cout<<ans;
break;
case’-’:
ans=n1-n2;
cout<<ans;
break;
case’
’:
ans=n1*n2;
cout<<ans;
break;
case’/’:
ans =n1/n2;
cout<<ans;
break;
case’%’:
ans=n1%n2;
cout<<ans;
break;
}
}
else
{
cout<<“Invalid operation. Try again.”;
}

}
while(ch!=‘x’ or ch!=‘X’);
return 0;
}

@architsuryavanshi hey,I have corrected your code,please see to it:

why b=0 is applied i am not able to understand it

@architsuryavanshi hey we have applied infinite while loop so to come out of that loop when x appears we use b,take b initially as 0 and after that when x appears in input do b=1 ,no when again loop starts we have applied condition when b=1 break the loop or come out of that loop.Dry run this code,you will get it.

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.