(all header files included)
using namespace std;
int main() {
char ch;
int n1,n2,result;
do
{
cin>>ch;
switch(ch)
{
case '+': cin>>n1>>n2;
result=n1+n2;
cout<<result<<endl;
break;
case '-': cin>>n1>>n2;
result=n1-n2;
cout<<result<<endl;
break;
case '*': cin>>n1>>n2;
result=n1*n2;
cout<<result<<endl;
break;
case '/': cin>>n1>>n2;
result=n1/n2;
cout<<result<<endl;
break;
case '%': cin>>n1>>n2;
result=n1%n2;
cout<<result<<endl;
break;
}
if(ch=='x'||ch=='X')
break;
else if((ch!='+')&&(ch!='-')&&(ch!='*')&&(ch!='/')&&(ch!='%'))
{
cout<<"Invalid Operation.Try Again"<<endl;
continue;
}
}while((ch!='x')and(ch!='X'));
return 0;
}
This is the code for the basic calculator question. The sample input passes correctly and generates the correct output . However none of the test cases pass.Please tell me my mistake?