Old 17th March 2002, 02:29   #1
sirchess
Senior Member
 
sirchess's Avatar
 
Join Date: Dec 2000
Location: Cyberspace
Posts: 132
Programming nightmare

As I haven't had any (official) programming training, I'm not sure about how the best way to go about this is.

For my calculator script, I've decided that the most flexible way to remember what's going on is to store the equation into a string, then use a function to derive what number to display from the equation. (as opposed to performing the math as the numbers are entered, which would require a complex system of variables and functions...)

This isn't the first time I've tried something like this...I've tried writing a calculator for C++ also...

The problem is that the calculator has to be able to use the order of operations, which means that I can't just plow straight through the string with a for loop. Right now I'm thinking of some sort of recursive function (i.e. calls itself when it reaches a parenthesis with only the substring in between the parentheses), but I'm just not even sure where to start...

Any help? TIA
sirchess is offline   Reply With Quote
Old 17th March 2002, 21:11   #2
Ice
Moderator Alumni
Americas Favorite Smut Peddler
 
Join Date: Jun 2000
Location: Sun Prarie, WI
Posts: 3,303
i'd change it into the language of what you're writing it in, and use an eval function to evaluate it..

I'd like to meet a mad man who makes it all seem sane
To work out all these troubles and what there is to gain
Ice is offline   Reply With Quote
Old 17th March 2002, 21:28   #3
sirchess
Senior Member
 
sirchess's Avatar
 
Join Date: Dec 2000
Location: Cyberspace
Posts: 132
Wow...never thought of that...thanks

But, does anyone know if MAKI has a string eval function? I don't see anything after a quick look through std.mi, but it's easy to miss it the first time...
sirchess is offline   Reply With Quote
Old 18th March 2002, 00:55   #4
Wilba
Junior Member
 
Wilba's Avatar
 
Join Date: Feb 2002
Posts: 20
I think it would be easier to perform the math as the numbers are entered, ie. like the Windows calculator app. You don't need to do any parsing, any order of operations stuff, you can even leave out parentheses to make life easier. Cuts down a lot of the work, like how to report errors in the equation, how to deal with using the result of previous calcs (an 'ans' variable?) etc.

If you're unfamiliar with recursive descent parsing in other languages like C++, doing it in Maki will be a bit of a challenge, but not impossible. You might get a good result in less time by going with the standard calculator interface (standard as in like 95% of them; a single numeric display, ten digit buttons and some operators).

Wilba

P.S. Here's a tip: floatToString() has crashed on me sometimes.
Wilba is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Skinning and Design > Modern Skins

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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