Time limit error

Write a program that works as a simple calculator.

1.It reads a character (ch)
2.If ch is among β€˜+’, β€˜-’, β€˜*’, β€˜/’ or β€˜%’ it furthur takes two numbers (N1 and N2 as input). It then performs appropriate appropriate operation between numbers and print the number.
3.If ch is β€˜X’ or β€˜x’, the program terminates.
4.If ch is any other character, the program should print β€˜Invalid operation. Try again.’ and seek inputs again (starting from character).–here is my codeβ€”

Hey @moksh
Mentioned the changes in comments : https://ide.codingblocks.com/s/360899 :slight_smile:

the ide link u send only shows hello world code send it again


In case it does not work


#include<iostream>
using namespace std;
int main() {
	long long int n1,n2,a,b,c,d,e;
	char ch; 
	// cin>>ch; //input it inside
	// cin>>n1; dont input here as we dont know if char is valid or not
	// cin>>n2;
	do {
		cin>>ch;
        if(ch=='+'){
        	cin>>n1;//input insode
            cin>>n2;
            a=n1+n2;
            cout<<a<<endl;
        }
		else if(ch=='-'){
            cin>>n1;//input insode
            cin>>n2;
			b=n1-n2;
			cout<<b<<endl;
		}
		else if(ch=='*'){
            cin>>n1;//input insode
            cin>>n2;
			c=n1*n2;
			cout<<c<<endl;
		}
		else if(ch=='/'){
            cin>>n1;//input insode
            cin>>n2;
            d=n1/n2;
			cout<<d<<endl;
		}
		else if(ch=='%'){
            cin>>n1;//input insode
            cin>>n2;
			e=n1%n2;
			cout<<e<<endl;
		}
        else {
            if(ch != 'x' && ch != 'X') {
                cout<<"Invalid operation. Try again."<<endl;
            }
        }
    }while( ch != 'x' && ch != 'X'); 
    // {remove this brackets not a while loop 

	// 	}
			
			
		
		
		return 0;
	}