Operating System - Tru64 Unix
1827769 Members
2709 Online
109969 Solutions
New Discussion

Re: C program in Unix environment

 
James I
Occasional Contributor

C program in Unix environment

How do i write a C program that produces a simple calculator with underflow and overflow protection.It should be able to perform 1 addition(+), subtraction(-), multiplication(x), or divsion(/) with normal positive or negative integers.
5 REPLIES 5
Michael Schulte zur Sur
Honored Contributor

Re: C program in Unix environment

Hi,

is there a reason you do not wish to use a calculator like dtcalc?
You could start with a loop asking for the first number then for the operation and then the second number. To test for overflow you could assign the result to a floating pint and compare that with the min/max limits of integer. Is that for programming practice?

greetings,

Michael
James I
Occasional Contributor

Re: C program in Unix environment

How do i write a C program that produces a simple calculator with underflow and overflow protection.It should be able to perform 1 addition(+), subtraction(-), multiplication(x), or divsion(/) with normal positive or negative integers.

With respect to my question,i just need a sample of a program for programming practice
Ravi_8
Honored Contributor

Re: C program in Unix environment

Hi,

Look into the book "C programming" by Kernighan and Ritchie (best known as K&R), after practicing you can write a calculator program.
never give up
Ralf Puchner
Honored Contributor

Re: C program in Unix environment

you need a parser and you need the knowledge of writing a signal handler and exception handling.

Help() { FirstReadManual(urgently); Go_to_it;; }
Eric van Dijken
Trusted Contributor

Re: C program in Unix environment

Don't expect us to do your homework.

But google is your friend: http://www.research.att.com/~bs/dc.c

Have fun. (And do read the book)
Watch, Think and Tinker.