Raised This Month: $32 Target: $400
 8% 

Calculator


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-23-2019 , 17:49   Calculator
Reply With Quote #1

I'm trying to make a calculator that only support multipling , adding and subtraction with a specified synax

Synax will look alike the following :-

{ 5.0 + { { 5 * 5 } - { 3 * 4 } } }

Regex pattren : "^^.*\{.*\d+(?:.*\..*\d*).*[*+-].*\d+(?:.*\..*\d*).*\}.*$"

Now i'm real confused on how to turn that string (equation) to an answer.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-23-2019 at 17:50.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-23-2019 , 19:04   Re: Calculator
Reply With Quote #2

Look into Shunting-yard algorithm and Postfix/Reverse Polish notation, that should help you.
__________________
klippy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-04-2019 , 17:11   Re: Calculator
Reply With Quote #3

Solved using regex

Fixed pattren : "^^.*(\{ *(\d+(?: *\. *\d* *| *))([\*\+\-]) *(\d+(?: *\. *\d* *| *))\}).*$"

Seems like I was missing brackets for string parsing.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-04-2019 at 17:51.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode