TLE Error in Basic Calculator

Please help resolve time limit exceeded error. The question:

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).


My code:

entry condition is wrong

if ch is X
then it should not enter inside loop but it will acc to your code

use and instead of or

I have replaced or with and, it is still showing TLE

send the link of your code

@asaurabh_26 my code: https://ide.codingblocks.com/s/609394

Your mistake
you have to take a and b only if ch is valid operator
if ch is ; then you need not to take a and b because in this case a and b will not be given to you

check modified Code below

Modified code

if you have further doubt
feel free to ask

Understood, thank you.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.