what is wrong with this code
Basic calculator code doubt
#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