Running in ide but showing error in code editor of problem

Basic calculator:
It’s running perfectly in IDE but showing error in code editor of problem, also it’s not showing what’s the error. So please checkout the code below and resolve my problem.

#include
using namespace std;
int main() {
char ch;
int n1,n2;
while(1)
{
cin>>ch;
switch(ch)
{
case ‘+’: cin>>n1;
cin>>n2;
cout<<n1+n2<<endl;
break;
case ‘-’: cin>>n1;
cin>>n2;
cout<<n1-n2<<endl;
break;
case '’: cin>>n1;
cin>>n2;
cout<<n1
n2<<endl;
break;
case ‘/’: cin>>n1;
cin>>n2;
cout<<n1/n2<<endl;
break;
case ‘%’: cin>>n1;
cin>>n2;
cout<<n1%n2<<endl;
break;
case ‘X’: exit(1);
case ‘x’: exit(1);
default: cout<<“Invalid operation. Try again.”;
break;
}
}
return 0;
}

Hello @anishanand3733,

Always share your code using Online Coding Blocks IDE.
The way you have shared it may introduce many syntax errors to it.
STEPS:

  1. Paste your code at https://ide.codingblocks.com/
  2. Save it there.
  3. Share the URL generated.

HI @anishanand3733 please save your code on ide.codingblocks.com and share the link.

Hello @anishanand3733,

In response to your code that you have shared with me on Chat,
there are 2 mistakes in your code:

  1. Leading error:
    exit(1)
    Solution:
    exit(0)
    Reason:
    The exit (0) shows the successful termination of the program and the exit(1) shows the abnormal termination of the program.

  2. Wrong Output:
    Missing end line statement.
    Solution:
    default: cout<<“Invalid operation. Try again.”<<endl;

Hope, this would help.
Give a like if you are satisfied.

1 Like

Hello @anishanand3733,

As I have already specified the mistakes in your code, why are sharing your code?
Do you still have any doubt left.

If yes, let me know.
Else, please mark this doubt as resolved.

BTW, I have corrected your code:


It will pass all the testcases.