Basic calculator

#include
using namespace std;
int main(){
char op;
cin>>op;
float num1,num2;
while(op!=‘x’||op!=‘X’){
cin>>num1>>num2;
switch(op){
case ‘+’:
cout << num1+num2;
break;
case ‘-’:
cout << num1-num2;
break;
case '’:
cout << num1
num2;
break;
case ‘/’:
if(num2!=0)
cout << num1/num2;
break;
case ‘%’:
if(num2!=0)
cout<<int(num1) % int(num2);
break;
default:
cout <<“Invalid operation. Try again.”;
break;
}} }
I am not able to find error in this code.

You need to use do while loop in this code, and take the input value of character first and check if its ‘x’ or ‘X’ , then simply return 0, or else if its not, then u simply have to take the input values of n1, and n2, and based on the character, you will have the result, This is the basic approach u need to follow up in your code.Basic snippet of code I m sharing here…

do
{
cin>>ch;
if(ch==‘x’ || ch==‘X’ )
{
return 0;
}
else
if(ch==’+’|| ch==’-’ || ch==’/’ || ch==’’ || ch==’%’)
{
cin>>n1>>n2;
}
switch(ch)
{
}
} while(ch!=‘X’|| ch!=‘x’||ch==’+’|| ch==’-’ || ch==’/’ || ch==’
’ || ch==’%’ );

#include
using namespace std;
int main(){
char op;
float num1,num2;
do{
cin>>op;
if(op==‘X’||op==‘x’){
return 0;
}
else
if(op==’+’||op==’-’||op==’’||op==’/’||op==’%’){
cin>>num1>>num2;}
switch(op){
case ‘+’:
cout << num1+num2<<endl;
break;
case ‘-’:
cout << num1-num2<<endl;
break;
case '
’:
cout << num1num2<<endl;
break;
case ‘/’:
if(num2!=0)
cout << num1/num2<<endl;
break;
case ‘%’:
if(num2!=0)
cout<<int(num1) % int(num2)<<endl;
break;
default:
cout <<“Invalid operation. Try again.”<<endl;
break;
}}while(op!=‘x’||op!=‘X’||op==’+’||op==’-’||op==’/’||op==’
’||op==’%’);
}
still not all test cases are passed.why?

I have edited the code… try to submit it now…