Basic Calculator Problem TimeLimit Issue

Hi, this is my code, https://ide.codingblocks.com/s/64975 for the 3rd and 4th test case, I am receiving time limit error. Please help

Hi SHOBHIT, pls simply your input and termination conditions. there are probably cases where your code is getting stuck into an infinite loop because of your inner while loop. For ex:

//INPUT
*
1
2
/
4
2
+
3
2
;
X

After “;” is read by cin in line 36 => ch = ‘;’
=> the control passes to parent while loop
=> while condition of parent loop becomes true and control moves into the while loop
=> now ch=’;’ is not equal to any of +,-,*,/,% so it again asks for ch in input
=> next ch is given as X which is again not equal to any of the 5 operators
=> and the loop goes on and on and on.

So you just need to simplify where you take ch input and where to terminate the while loop.

Hope this helps :slight_smile:

Hey Shobhit, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.