Don't know in your execution 2 cases are failing

when i m try with same set of inputs outputs are same
code:
#include

using namespace std;

int main()
{
int n1,n2,res;
char ch;
label:
cin>>ch;

switch(ch)
{
    case '+': cin>>n1>>n2;
              res=n1+n2;
                cout<<res<<endl;
     goto label;
    case '-': cin>>n1>>n2;
             res=n2-n1;
                cout<<res<<endl;;
    goto label;
    case '*': cin>>n1>>n2;
            res=n1*n2;
                 cout<<res<<endl;
    goto label;
    case '/':
        cin>>n1>>n2;
        if(n2!=0)
        {res=n1/n2;
        cout<<res<<endl;}



    goto label;
    case '%': cin>>n1>>n2;
      if(n2!=0)
      {
        res=n1%n2;
        cout<<res<<endl;
      }
    goto label;
    case 'X': break;
    case 'x': break;
    default: cout<<"Invalid operation. Try again"<<endl;
             goto label;
 }

return 0;

}

case 2 and 4 are failing on submission

Hey Ajay, case 2 will gets pass if you put . after “again”. If you see carefully output should be Invalid operation. Try again. instead of Invalid operation. Try again

Even if you correct it, all your testcases will not pass.
consider this case
+ 3 1
3 3 1
x

Your Output
4
Invalid operation. Try again.
Invalid operation. Try again.
Invalid operation. Try again.

Correct Output
4
Invalid operation. Try again.

Modify your code according to this.

1 Like

hey Ajay, 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.

Sir in question they have asked if ch is among + - * / or% it further take to number that means in we enter 3 then its invalid means it will again ask for input which is again invalid in that my output is correct
However if we take case that whatever the operator user can inter value than it will wrong
And i have downloaded test cases in that output are same

code:
#include

using namespace std;

int main()
{
int n1,n2,res;
char ch;
label:
cin>>ch;

switch(ch)
{
    case '+': cin>>n1>>n2;
              res=n1+n2;
                cout<<res<<endl;
     goto label;
    case '-': cin>>n1>>n2;
             res=n2-n1;
                cout<<res<<endl;;
    goto label;
    case '*': cin>>n1>>n2;
            res=n1*n2;
                 cout<<res<<endl;
    goto label;
    case '/':
        cin>>n1>>n2;
        if(n2!=0)
        {res=n1/n2;
        cout<<res<<endl;}



    goto label;
    case '%': cin>>n1>>n2;
      if(n2!=0)
      {
        res=n1%n2;
        cout<<res<<endl;
      }
    goto label;
    case 'X': break;
    case 'x': break;
    default: cout<<"Invalid operation. Try again."<<endl;
             goto label;
 }

return 0;

}

hey Ajay, yes you are right, it should not take further numbers if it is getting character other than these 4 arithmetic characters.

There is small mistake in your code, when ch= - than it should be n1-n2 not n2-n1
Please make this small change and your code will pass the remaining testcase.

Thanks …it’s done now…all cases correct