Basic calculator-TLE please help me out

#include
using namespace std;
int main() {
int N1,N2;
char ch;
int op;
cin>>ch;
do{
if(ch==’+’)
{
cin>>N1;
cin>>N2;
op=N1+N2;
cout<<op<<endl;
}
else if(ch==’-’)
{
cin>>N1;
cin>>N2;
op=N1-N2;
cout<<op<<endl;
}
else if(ch==’’)
{
cin>>N1;
cin>>N2;
op=N1
N2;
cout<<op<<endl;
}
else if( ch==’/’)
{
cin>>N1;
cin>>N2;
op=N1/N2;
cout<<op<<endl;
}
else if( ch==’%’)
{
cin>>N1;
cin>>N2;
op=N1%N2;
cout<<op<<endl;
}
else if(ch==β€˜X’ || ch==β€˜x’)
{
break;
}
else{
cout<<β€œInvalid operation. Try again.”<<endl;
cin>>ch;
}

} while(ch!='\0');
return 0;

}

hello @sakshi.saxena
pls save ur code here ->

and share the link with me

image
put this cin>>ch, out of the else statement

1 Like