473,408 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Calculator

Hello,

I wanna make a calculator where i can give the input in one word. for
example : (15*3) / (2+3)
I think i most read this in as a string and then share it in different parts
to do the calculation. But i don't now how tho start with it. Can somebody
help me.

Thanks in advanced.
Nov 14 '05
58 4043

"Chris Croughton" <ch***@keristor.net> wrote
Memory you don't own is hardware.


I own all of it, I paid for it when I bought the computer.

Schoolboy response to a point which is difficult and may well be beyond your
capacity to understand.
How about reading what Derrida had to say on metaphor and thinking, and
coming back when you have a qualified opinion on the subject?
Nov 14 '05 #51

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.ca> wrote

It is clear that "function" in mathematics and "function" in C are
never going to be reconcilable, so the exercise is pointless.
No, we use the term "function" in programming because there is a resemblance
to the mathematical term.
An extremely pedantic mathematician might say that sqrt() isn't a square
root as he understands it, because sqrt(2) * sqrt(2) is unlikely to equal 2,
and pow(sqrt(-1), sqrt(-1)) will cause the computer to throw a wobbly,
whilst to the mathematican this is a perfectly normal real. However most
mathematicians would say that there is sufficient similarity between a C
sqrt() and a mathematical square root to use the same words.
The closest you would be able to get on the mathematics side
would not be "functions" but rather at most "functions which are
representable as the union of formulae applied over limited ranges".
Every programming function must have a domain which is less than the total
set of integers, or of real numbers. In practise this isn't much of a
problem - if we want to calculate pow(100000, 10000000000000) the computer
won't let us, but in reality we normally want to work with low numbers that
can be represented in C doubles.
The problem comes when the word "function" is used for things like exit(),
assert() and free().
You could design a proramming langage in which all functions are "pure
functions", or mathematical functions. So they return a vaule which is
defined solely by their arguments, and have no side effects. This wouldn't
necessarily be a bad idea, but you would have major efficency problems - the
sort routine would have to return a sorted copy of the list it was passed,
for instance.
So I've chosen to define "function" in a different way.
But I am not oblivious to the point that there is already a largely
syntactic definition of "procedure" and "function". Unfortunately people
don't seem to be able to grasp that my definitions are refinements of the
concepts (as British state is to American state), not reuse of the same
terms (as British ass is to American ass). This is frustrating but not
totally unexpected. It generally takes a bit of plugging away before ideas
click.
even with that, I would be interested to see the mathematical
union-of-formulaes function corresponding to something as relatively
simple in C as "the next prime number after the whole number given as
the argument".

Only God can count in primes. That is one of the mysteries of mathematics.

Why should some really simple rules produce very non-simple results? Have
you written a "prime spiral" program, BTW?
Nov 14 '05 #52

In article <42***************@yahoo.com>, CBFalconer <cb********@yahoo.com> writes:

You never had to use old-fashioned Cobol, did you? The closest
thing to a function or procedure is 'perform', and there is no
parameter passing mechanism whatsoever.
That must be some *mighty* "old-fashioned" COBOL. I haven't been
able to track down the original CODASYL report, but one source
claimed that CALL ... USING was introduced "early in the development"
of COBOL, and another that COBOL has "always" had CALL ... USING.

Nested programs were only standardized in COBOL 85, but I'm not aware
of any COBOL version where you couldn't call other programs - they
just had to be in separate source files.
So you create some global
variables for the use of the performed paragraph, stuff values in
them, and use self discipline to not use them for other purposes.


That certainly was the dominant practice (though some people prefer
to use sections rather than paragraphs - a distinction of importance
only to COBOL programmers), and as far as I can tell still is. And
prior to the 2002 standard there was no standard way to have
recursive (including mutually recursive) calls, though many implemen-
tations supported them as an extension.

But you could also write your application as an initial program and
subprograms, in COBOL parlance, which would all run in the same "job"
or "process". This is still somewhat more limited than C; besides
the lack of recursion, there's no equivalent of "static" (all
program names are externally visible) and while some implementations
(and, I think, the X/Open standard, though not the ISO standard)
provided a way to pass a return code, a program call couldn't be used
in an expression, so there was no function-like behavior. (Now COBOL
has support for user-defined functions.)

Traditional BASIC had no way to pass parameters to subroutines, did
it? They had to be global-scope variables (because there wasn't any
other scope).

At any rate, though, I agree that in these languages common practice
was to use global-scope variables for passing parameters, because the
language either didn't provide a parameter-passing mechanism or made
it cumbersome.

--
Michael Wojcik mi************@microfocus.com

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
-- David Bonde
Nov 14 '05 #53
Malcolm wrote:
"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.ca> wrote
It is clear that "function" in mathematics and "function" in C are
never going to be reconcilable, so the exercise is pointless.

No, we use the term "function" in programming because there is a resemblance
to the mathematical term.
An extremely pedantic mathematician might say that sqrt() isn't a square
root as he understands it, because sqrt(2) * sqrt(2) is unlikely to equal 2,
and pow(sqrt(-1), sqrt(-1)) will cause the computer to throw a wobbly,
whilst to the mathematican this is a perfectly normal real. However most
mathematicians would say that there is sufficient similarity between a C
sqrt() and a mathematical square root to use the same words.


Or the term in computing could come from use usage of the work function
as, "the function of the of the engine is to convert chemical energy in
to mechanical energy generating heat as a side effect which is used to
heat the interior of the car." So you have a function with a side effect.
The closest you would be able to get on the mathematics side
would not be "functions" but rather at most "functions which are
representable as the union of formulae applied over limited ranges".


Every programming function must have a domain which is less than the total
set of integers, or of real numbers.


False. The domain of a function can include all possibly values of input
parameter(s). For example:

int negative(int i)
{
return i < 0;
}
In practise this isn't much of a
problem - if we want to calculate pow(100000, 10000000000000) the computer
won't let us, but in reality we normally want to work with low numbers that
can be represented in C doubles.
The problem comes when the word "function" is used for things like exit(),
assert() and free().
In other languages those would be called procedures or similar. However,
another example of the word function from outside of computing, "the
function of the grommet is to prevent the cable being damaged as it
passes through the case." Another use of the word function that has
nothing to do with returning a value but matches well with the use in C.
You could design a proramming langage in which all functions are "pure
functions", or mathematical functions. So they return a vaule which is
defined solely by their arguments, and have no side effects. This wouldn't
necessarily be a bad idea, but you would have major efficency problems - the
sort routine would have to return a sorted copy of the list it was passed,
for instance.
Unless you don't define the sort routine as a pure function.
So I've chosen to define "function" in a different way.
But I am not oblivious to the point that there is already a largely
syntactic definition of "procedure" and "function". Unfortunately people
don't seem to be able to grasp that my definitions are refinements of the
concepts (as British state is to American state), not reuse of the same
terms (as British ass is to American ass). This is frustrating but not
totally unexpected. It generally takes a bit of plugging away before ideas
click.


All you will do by continuing to try to redefine terms with well known
meanings is annoy people and get yourself plonked by people who could
help you with problems.
even with that, I would be interested to see the mathematical
union-of-formulaes function corresponding to something as relatively
simple in C as "the next prime number after the whole number given as
the argument".


Only God can count in primes. That is one of the mysteries of mathematics.

Why should some really simple rules produce very non-simple results? Have
you written a "prime spiral" program, BTW?


Look at chaos theory. There are simple rules that produce very
non-simple results, and a whole branch of mathematics dedicated to them.
I think you missed Walters point, which is that some pure functions that
can be relatively easily expressed in a high level computer language are
not so easy to express in mathematics.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #54
Michael Wojcik wrote:
CBFalconer <cb********@yahoo.com> writes:

You never had to use old-fashioned Cobol, did you? The closest
thing to a function or procedure is 'perform', and there is no
parameter passing mechanism whatsoever.


That must be some *mighty* "old-fashioned" COBOL. I haven't been
able to track down the original CODASYL report, but one source
claimed that CALL ... USING was introduced "early in the development"
of COBOL, and another that COBOL has "always" had CALL ... USING.


I used it somewhere around '87 or so, but IIRC it was called COBOL
68. That was it for that installation.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

Nov 14 '05 #55
"Malcolm" <re*******@btinternet.com> wrote:
"Flash Gordon" <sp**@flash-gordon.me.uk> wrote
.
So a function calculates something - ie is a number of set of numbers
that is defined by the arguments.


What if the value returned is determined by by HW rather than parameters?
For example, getchar which has *no* parameters.

Exactly. sqrt() is obviously a function. Is "get_mouse_position()" also a
function? I'm saying it is not, it is a procedure.


How about get_window_pixel(window, x,y)? It first needs to calculate the
global coordinates which are the equivalent of x and y in that window;
then fetch the pixel at those global coordinates; then return that pixel
to the caller.

How about a dummy function, for example the one I just wrote, which
allows one (off-topically, but illustratively) to use the old-style File
common dialogs under MS-Windows? It calculates nothing, interacts with
nothing, does nothing, in fact, but return FALSE.

The distinction you make is meaningless.

Richard
Nov 14 '05 #56
"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote

How about get_window_pixel(window, x,y)? It first needs to calculate the
global coordinates which are the equivalent of x and y in that window;
then fetch the pixel at those global coordinates; then return that pixel
to the caller.
It depends how the window parameter is defined. If the function cannot be
written without accessing global memory, then it is in one class, if it
takes all its arguments as parameters and doesn't alter them, it is a pure
function, if it is in between it is in another class (which I've called
function, to distinguish from pure function).
How about a dummy function, for example the one I just wrote, which
allows one (off-topically, but illustratively) to use the old-style File
common dialogs under MS-Windows? It calculates nothing, interacts with
nothing, does nothing, in fact, but return FALSE.
That's a pure function.
The distinction you make is meaningless.

Then the term "pure function" is also meaningless.
Nov 14 '05 #57
On Sat, 14 May 2005 20:34:01 GMT, Keith Thompson <ks***@mib.org>
wrote:

<snip>
In my (perhaps somewhat limited) experience, these meanings of the
terms "procedure" and "function" are nearly universal.
Plus the similar 'subroutine' and 'function' in FORTRAN, wide but not
universal. PL/I used 'proc(edure)' for both valued and nonvalued.
IIRC algol68 used 'routine' for both. BCPL used 'routine' and had
everything valued, as its untyped word. LISP used only 'function' and
effectively had everything valued although that value can be the
special value NIL, which is arguably like the nonexistent or at least
unexpressible value of void type in C.
There is a related concept that may be close to what you're talking
about: a "pure" function. A pure function, loosely, is one that
computes a result using only its explicit parameters; it doesn't refer
to any global variables, none of its local variables are "static" in
the C sense, it has no side effects. The mathematical functions are
examples of this; time() is not, since it refers to an implicit
global. If an optimizer sees two calls to a pure function with the
same arguments, it can safely replace them with a single call.
Except in C for errno, as Chris Torek has already noted.
Neither Pascal nor C makes any language-level distinction between
"pure" functions and other functions. (Ada does, if I recall
correctly.)

Ada for (valued) functions prohibits any (formal) parameters in modes
that allow 'direct' writing whereas nonvalued procedures can have
'out' or 'in out' parameters. Both allow 'access' parameters,
effectively pointers, which can be written through, and (in a package)
persistent variables. And it allows a pragma to optionally specify
Pure which prohibits all persistent state, not just side-effects.

Fortran beginning with F90 allows FUNCTIONs to be declared PURE which
enforces prohibitions against language-recognized side-effects and
redundant calls may be elided; F95 adds ELEMENTAL which further allows
different calls for whole-array operations to be done in parallel. The
usual math library functions like SIN have this attribute.

- David.Thompson1 at worldnet.att.net
Nov 14 '05 #58

"Dave Thompson" <da*************@worldnet.att.net> wrote
Ada for (valued) functions prohibits any (formal) parameters in modes
that allow 'direct' writing whereas nonvalued procedures can have
'out' or 'in out' parameters. Both allow 'access' parameters,
effectively pointers, which can be written through, and (in a package)
persistent variables. And it allows a pragma to optionally specify
Pure which prohibits all persistent state, not just side-effects.

Thank you.
Nov 14 '05 #59

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: mwh | last post by:
Hi. If you remember, I posted Expressons Help. Now I am making a calculator with javascript. I can't get this to work: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
6
by: Rafael | last post by:
Hi Everyone, I need some help with my calculator program. I need my program to do 2 arguments and a 3rd, but the 3rd with different operators. Any help would be great. Here is my code.... ...
3
by: Paul | last post by:
I want to make a simple calculator program but dont know where to get started. This is not GUI but a simple terminal program. It would get input like this Enter number: 5 + 10
3
by: Art | last post by:
Hi, In part of my application the user may need to do a simple arithmetic calculation in order to get the value to put in a text box. I was thinking that it would be good if I could display the...
3
by: PieMan2004 | last post by:
Hi, ive been looking for a solid java community to help me when im tearing out my hair :) Basically ive constructed a GUI that has to represent the same look and functions of the typical windows...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
19
by: TexasNewbie | last post by:
This was originally just a calculator without a decimal point. After I added the decimal, it now tells me invalid second number. //GUI Calculator Program import javax.swing.*; import...
5
Deathwing
by: Deathwing | last post by:
Hi everyone one I'm playing around with trying to make an expense calculator. I would like it so that the user can keep enter expenses until they have no more expenses. Then I would like for the...
3
by: itsmichelle | last post by:
This is a very primative code of a java swing calculator. I have assigned all the number buttons and the operator buttons and I can add, subtract, multiply, and divide two numbers together. However,...
3
by: mandy335 | last post by:
public class Calculator { private long input = 0; // current input private long result = 0; // last input/result private String lastOperator = ""; // keeps track of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.