For this question, I am using switch case but getting this error:
runguard: warning: timelimit exceeded (wall time): aborting command
runguard: warning: command terminated with signal 15
my code:
#include
using namespace std;
int main() {
char ch;
cin.get(ch);
while((ch != 'X') || (ch != 'x'))
{
switch(ch)
{
case '+' :
{
int a,b;
cin>>a>>b;
long long ans = a+b;
cout<<ans<<"\n";
break;
}
case '-' :
{
int a,b;
cin>>a>>b;
cout<<(a-b)<<"\n";
break;
}
case '*' :
{
int a,b;
cin>>a>>b;
long long ans = a*b;
cout<<ans<<"\n";
break;
}
case '/' :
{
int a,b;
cin>>a>>b;
cout<<(a/b)<<"\n";
break;
}
case '%' :
{
int a,b;
cin>>a>>b;
cout<<(a%b)<<"\n";
break;
}
default :
cout<<"Invalid operation. Try again.\n";
break;
}
cin.get(ch);
}
return 0;
}