By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,479 Members | 1,729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,479 IT Pros & Developers. It's quick & easy.

How can I make a calculator in C programming?

P: n/a
Hello,
I'm a new learner.I want to know how to make a calculator in C
programming.
I hope someone can help me .Thanks!
Nov 3 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
JOYCE wrote:
Hello,
I'm a new learner.I want to know how to make a calculator in C
programming.
I hope someone can help me .Thanks!

You haven't given us very much information. Thoroughly describe the
project as you envision it, and tell us what you have already tried.


Brian
Nov 3 '08 #2

P: n/a
On 3 Nov, 08:59, JOYCE <zzzzzz90...@126.comwrote:
* * * *I'm a new learner.I want to know how to make a calculator in C
programming.
I hope someone can help me .Thanks!
It might be easier to start with what's called Reverse Polish
Notation (look it up).

Here expressions to be evaluated (calculated) are written
like this

2 2 + (calculates 2 + 2)
3 4 4 + * (calculates 3 * 4 + 4)

the rules are simple:
Read a symbol
if it's a number push it on a stack
if it's an operator remove the top two items from the stack
and apply the operator. Put the result on the stack
When you run out of symbols print what's on the stack

So you need a stack and a way to read symbols.

good luck!
--
Nick Keighley
Nov 3 '08 #3

P: n/a
"JOYCE" writes:
I'm a new learner.I want to know how to make a calculator in C
programming.
There is one in _The C Programming Language_ by Kernighan & Ritchie, fondly
called simply K&R. Any C programmer must eventually have that book so this
may be a good reason to get it now.
Nov 3 '08 #4

P: n/a
Nick Keighley wrote:

3 4 4 + * (calculates 3 * 4 + 4)
Actually this would calculate 3 * (4 + 4). This is how the stack
looks for every symbol read ('>' prefixes a read element, '='
prefixed a element resulting from a operation, replacing the
elements consumed by the operation; stack grows downwards):
>3
3
>4
3
4
>4
3
4
4
>+ -operator '+' performs addition on the
two topmost elements of the stack, yielding

3
=8

3
8
>* -operator '*' performs multiplication on the
two topmost elements of the stack, yielding

=24

Wolfgang Draxinger
--
E-Mail address works, Jabber: he******@jabber.org, ICQ: 134682867

Nov 3 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.