Basic calculator code doubt


what is wrong with this code

#include
using namespace std;
int main() {
while(1)
{
char ch;
cin>>ch;
if(ch==’+’||ch==’-’||ch==’*’||ch==’/’||ch==’%’)
{
long long int n1,n2,n3;
cin>>n1>>n2;

		if(ch=='+')
		n3=n1+n2;
		else if(ch=='-')
        n3=n1-n2;
		else if(ch=='*')
		n3=n1*n2;
		else if(ch=='/')
		{
			if(n2==0)
			break;
			else
			n3=n1/n2;
		}
		else if (ch=='%')
		{
			if(n2==0)
			break;
			else
			n3=n1%n2;
		}
		cout<<n3<<endl;
	}
	else if(ch=='X'||ch=='x')
	break;

	else{
		cout<<"Invalid operation. Try again."<<endl;
		continue;
	}
}
return 0;

}

can you find the difference?
again, i repeat. Please, read the question properly.
There is a set format of outputs in question.
so, follow them

btw your mistake is a full stop β€œ.”
you are printing:
β€œInvalid operation. Try again”

and you are required to print:
β€œInvalid operation. Try again.”

Hope, this would help.

1 Like