Eval function wrong calculating | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 3

Eval function wrong calculating

If user calculate 5 + 5 * 10 it's gonna return 55, which is wrong it's should be 100. And how to fix it https://code.sololearn.com/WRh3fh8viTWq/?ref=app

15th Dec 2021, 4:35 AM
EsaKurniawan
7 Answers
+ 4
Nop it's not wrong It also follows BODMAS rule of basic maths so if you do (5+5)*10 then it will first solve bracket and return 100 else it will first do 5*10 then add 5 to give 55
15th Dec 2021, 4:37 AM
Ayush Kumar
Ayush Kumar - avatar
+ 3
EsaKurniawan add a bracket button also in your calculator. I allready told (5+5)*10 will give you 100
15th Dec 2021, 4:42 AM
Ayush Kumar
Ayush Kumar - avatar
15th Dec 2021, 4:38 AM
Simon Sauter
Simon Sauter - avatar
0
There's nothing to fix apart from your math skills.
15th Dec 2021, 4:40 AM
Simon Sauter
Simon Sauter - avatar
0
How to make it equal 100
15th Dec 2021, 4:40 AM
EsaKurniawan
0
Or just hit "=" after "5+5".
15th Dec 2021, 4:47 AM
Simon Sauter
Simon Sauter - avatar
0
Thanks a lot all of you guys for helping me I'll try your advice
15th Dec 2021, 4:49 AM
EsaKurniawan