Basic calculator

i am not able to understand whast wrong in
this solution
#include
using namespace std;
int main() {
char ch;
int N1, N2, ans;
do{
cin>>ch;
cin>>N1;
cin>>N2;
if(ch==’’){
ans=N1
N2;
cout<<ans<<endl;
}
else if(ch==’-’){
ans=N1-N2;
cout<<ans<<endl;
}
else if(ch==’+’){
ans=N1+N2;
cout<<ans<<endl;
}
else if(ch==’%’){
ans=N1%N2;
cout<<ans<<endl;
}
else if(ch==’/’){
ans=N1/N2;
cout<<ans<<endl;
}
else{
cout<<β€œInvalid operation. Try again.”<<endl;
}

}
while(ch=='x' || ch=='X');
return 0;

}

@Muazul-Hasan-1306054032879326 while loop should break if ch ==β€˜x’ or ch==β€˜X’ but you are running your while loop for opposite.and use simple while loop here, do-while may give wrong answer by printing an extra line here.

done that still output is wrong

@Muazul-Hasan-1306054032879326 you have to take N1 and N2 input only when ch is valid. i have updated your code a little look at this https://ide.codingblocks.com/s/269520

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.