473,399 Members | 3,302 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,399 software developers and data experts.

How can I make a calculator in C programming?

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
4 5883
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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.... ...
58
by: Flipke | last post by:
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...
4
by: Joe | last post by:
Can someone tell me how to call the system calculator in windows XP, I am programming with VB.Net. I am writing a program and I would like to let the user have access to the calculator in windows....
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...
3
by: Ron | last post by:
Hello, I made a vb calculator just a simple one using code like this. ansmult = txtinput.text * txtinput.text ansplus = txtinput.text + txtinput.text but my calculator works like this. I...
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...
1
by: Lamya | last post by:
hi, how can i make a calculator on a C programming?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...

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.