+ 3
Time limit exceeded
I made a calculator program in C, but it said time limit exceeded when running it. Please help me to increase the time limit
13 odpowiedzi
+ 4
More than likely your time usage is due to a bug. If you link your code here, we might find it so your program works.
+ 5
you cannot increase the time limit.
sololearn sends the code to their server,its run there and output is returned back to codeplayground.
this means your code has a limited runtime
+ 5
getch is what is causing your issue. It is a non-standard function so is hanging your program. Use the standard equivalent: getchar. To enter in Playground, run with: 5 6*
+ 3
Harsh
I have rectified your all errors and made it working here.Input pattern is changed as it was the bug,so check the C-comments section inside the program for more details .Program logic remains same.No change to your program logic.Check the link given far below to the program for further details.
The program explains in details for each step reporting errors and the correction made against it in form of C-comments. Run the program and execute it to get the output.
The main cause or bug of your program not working here is precedence order to read input from user.
Check the program below for detailed explanation and a suggestion from my side would be read the C-comments in code section of the program along with C-Comment section for detail understanding. Hope it clarifies your doubt.
The link to the program is given below here, feel free to look:-
https://code.sololearn.com/cxC13o2OL6r7/?ref=app
+ 2
One of the reason can be program goes in an infinte loop.
+ 2
my program runs in android dosbox
+ 2
Thank you
+ 1
https://code.sololearn.com/cX04BG4Uio56/?ref=app
0
Usually this happens is because of an infinite loop. It takes a lot for a normal program to take 5 seconds to compile and run
0
I'd have stuck with scanf()...
More importantly, you need to handle if x is not +, -, /, or *. Most would suggest a case default, but may I suggest a while statement, eg:
char x = 0;
...
while (x != '-' && x != '+' && x != '*' && x != '/')
scanf("%c", &x); /* or x = getchar() if you prefer */
Just makes life easier to avoid invalid input. Although you should usually have a default case.
You also need to format your code or you'll lose track of it. It's not very legible.
Anyway, good luck!
0
I made a program for pattern and it is not running and say time exceeded