?
Solved

Calculator

Posted on 1997-03-09
12
Medium Priority
?
201 Views
Last Modified: 2010-04-16
I'm desperately in need of a program which does simple mathmetical calclations. But, the program has to be able to recognize operation priorities.Eg. : If we have 3+4*5-6/7, it will have to multiply 4 & 5, and divide 6 by 7 first. Then the plus and minus.
0
Comment
Question by:ThEGuy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 2

Expert Comment

by:javiertb
ID: 1215252
You could just do it yourself by parsin the string in this way:
1st- Move through the string storing the individual number just before the sign.
2nd- If the sign was '*' or '/' then read the following number, do the calculation and substitute the two nunbers and the sign with the result in the string (always keeping track of the position with appropiate counters).
3rd-Move to the beginning of the string and do the 2nd step but this time looking for '+' or '-'

Hope this helps.

0
 

Author Comment

by:ThEGuy
ID: 1215253

0
 

Expert Comment

by:dpuryear
ID: 1215254
Are you just looking for a more detailed, better algorithm or are you looking for complete source code?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Expert Comment

by:MasterBo
ID: 1215255
I would again recommend getting Pascal snippets, or SWAG
colelction, from garbo.uwasa.fi, in /pc directory.
Simple parsing procedures, one of which you need, has been
implemented several times in SWAG. Please visit Garbo site.

0
 

Author Comment

by:ThEGuy
ID: 1215256
dpuryear, actually i'm lookin for a complete soursecode if possible in graphic mode.
0
 
LVL 4

Expert Comment

by:nils pipenbrinck
ID: 1215257
25 points for a complete string-evaluator source is not much.

However, some years ago I wrote such an algorithm.
I used exactly the algorithm raviert gave you. It wasn't more than 200 lines of code.
0
 

Expert Comment

by:MasterBo
ID: 1215258
If you need code written ab initio, yes, 25 points is too
little. However, did you ever browsed SWAG collection?

It's not library, it's source code collection.

By the way, graphics, in my opinion, is not related to
the problem. How does graphics and string parsing interfere?

0
 
LVL 1

Accepted Solution

by:
mrosen earned 60 total points
ID: 1215259
You need to first parse the operation and identify tokens (easy when your number is like '3' but hard when you have 03.02). To do that in order, you need to define stuff using backus-nauer notation, which is a recursive definiction of your input. It's like creating a complier for numbers.
0
 

Expert Comment

by:kilobug
ID: 1215260
I've made a full unit wich recognize very complex strings, with variables, mathematic functions, logical operators, ....

If some of you wants it, only ask it by mail....

Bye
0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1215261
I have an old unit somewhere which could do mathematical parsing.
As far as I remember it could also do functions such as sin and cos and so on. I used it to write a shareware program many years ago (graph3d). Anyway, if you want it, just tell me.
0
 

Expert Comment

by:wpmaurice
ID: 1215262
Assuming that the function's level of difficulty is that in your question. You can input the calculation as a string, then use a double loop to scan for the operator (+,-). Next, perform the calculations by means of array manipulations. A string is actually an array of characters.
0
 

Expert Comment

by:renkens
ID: 1215263
The first proposed answer is of course the right one.
In constructing a (simple) DBMS I build a expression evaluator
myself (not for sale for 25 points). But some tips :
By or rent or get the book 'Algoritmes + Datastructures = Programs' from Niklaus Wirth. It contains great material on
constructing a parser for a given syntax diagram.
Then make the syntax diagram for youre expressions and code
the procedures using the rules from the book.
At last add the needed arithmic to you're parser procedures and
the job is doned !
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question