Kindly help me with this…My code does not pass all test cases
Basic calculator
Check the Output format for Invalid Operation case.
Did that…still one of the test cases failed…
You have taken input variables as unsigned long long int, so if their ans is negative after some operation you won’t get the desired ans.
Okk…Got it…thanks…doubt resolved
what is wrong in my code can you tell please
only 1 test case got passed
#include
using namespace std;
int main()
{
long long int n,m;
char ch;
do
{ cin>>ch;
if(ch==‘X’ || ch==‘x’)
{break;}
switch(ch)
{
case ‘+’: {cin>>n>>m;
if(n<=100000000 && n>=0 && m>=0 && m<=100000000)
{cout<<n+m<<endl;} break;}
case ‘-’: {cin>>n>>m;if(n<=100000000 && n>=0 && m>=0 && m<=100000000)
{cout<<(n-m)<<endl;} break;}
case '’: {cin>>n>>m;
if(n<=100000000 && n>=0 && m>=0 && m<=100000000)
{cout<<nm<<endl;} break;}
case ‘/’: {cin>>n>>m;
if(n<=100000000 && n>=0 && m>0 && m<=100000000)
{cout<<(n/m)<<endl;}
break;}
case ‘%’: {cin>>n>>m;
if(n<=100000000 && n>=0 && m>0 && m<=100000000)
{cout<<(n%m);}
break;}
default :{cout<<“Invalid operation. Try again.”;
break;}
}
}while(1);
return 0; }
what is wrong in this code only one test case got passed
#include
using namespace std;
int main()
{
long long int n,m;
char ch;
do
{ cin>>ch;
if(ch==‘X’ || ch==‘x’)
{break;}
switch(ch)
{
case ‘+’: {cin>>n>>m;
if(n<=100000000 && n>=0 && m>=0 && m<=100000000)
{cout<<n+m<<endl;} break;}
case ‘-’: {cin>>n>>m;if(n<=100000000 && n>=0 && m>=0 && m<=100000000)
{cout<<(n-m)<<endl;} break;}
case '’: {cin>>n>>m;
if(n<=100000000 && n>=0 && m>=0 && m<=100000000)
{cout<<nm<<endl;} break;}
case ‘/’: {cin>>n>>m;
if(n<=100000000 && n>=0 && m>0 && m<=100000000)
{cout<<(n/m)<<endl;}
break;}
case ‘%’: {cin>>n>>m;
if(n<=100000000 && n>=0 && m>0 && m<=100000000)
{cout<<(n%m);}
break;}
default :{cout<<“Invalid operation. Try again.”;
break;}
}
}while(1);
return 0; }