pocket calculator program


Hello,

I am trying to do a calculator program :

The program should read in a text string containing a list of numbers separated by + or - and output the sum. The program should also tell how many positive numbers and how many negative (subtracted) numbers there are.

Example:
input: 8.4 + 2.6 - 3.5 + 1
output: result = 8.5, positive numbers: 3, negative numbers: 1.

The input cannot contain any other operators than + and -. Spaces are allowed.

The program should be organized so that main reads the input as a single text string and outputs the results. The interpretation of the text string and calculation of results should be in a separate sub-function. Do not use global variables.

Tip: the function atof can read a number from a text string. Anything that comes after the number is ignored by atof.

I have asked several people about this but none of them could how to do it . especially with atof;

Any suggestions and code are greatly appreciated.

Try the shunting-yard algorithm, it worked for me when I tried the same problem (but with multiplication, division and powers added to the functionality):
http://en.wikipedia.org/wiki/Shunting-yard_algorithm
Topic archived. No new replies allowed.