Doubt in the code of Basic calculator

Sir , Output was the prorer.
#include
#include
#include<stdio.h>
using namespace std;

int main()
{
char ch;
while(scanf("%c",&ch)!=EOF){
if(ch==’+’||ch==’-’||ch==’’||ch==’/’||ch==’%’)
{
int n1,n2;
switch(ch){
case’+’:{
cin>>n1>>n2;
cout<<n1+n2<<endl;break;}
case’-’:{
cin>>n1>>n2;
cout<<n1-n2<<endl;break;}
case’
’:{
cin>>n1>>n2;
cout<<n1*n2<<endl;break;}
case’/’:{
cin>>n1>>n2;
cout<<n1/n2<<endl;break;}
case’%’:{
cin>>n1>>n2;
cout<<n1%n2<<endl;break;}
break;
return 0;
}
}
else {cout<<“Invalid operation.Try again,”<<endl;}

}
while(ch!=‘x’&&ch!=‘X’);
return 0;
}

hey @76rahul257, your code is not correct. Take idea from this code https://ide.codingblocks.com/s/95379.

In the given code ,I d not understand the meaning and purpose of “default”.Why we use it ,in that place can we apply any condition.And what is the meaning of “while(1)”

hey @76rahul257, default case gets executed when ch is not matched with +,-,*,/,%,x,X. We take while(1) so that we can take input of any number of character till we get x or X.

Thank you very much…

hey @76rahul257 , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt as resolved

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.