Reading and Storing Fractions

closed account (365X92yv)
I'm trying to write a program that can do fractional arithmetic. I need to be able to input complex functions to do this. My goal is to be able to input something like this....

Input:
(1/2 + 2/3) - (2/4 * 1/4)

What I want is to try and store each part in its own seperate variable, then calculate each individual fraction, then take those seperate variables and do the arithmetic on the fractions.

For instance, declare 5 variables, one for the numerator, one for the denominator, one for the double value of the fraction, one for storing the operator (i.e +, -, /, *), and then one for storing the end result of the arithmetic.

Example:

int fracTop, fracBot;
double fraction;
char fracOperator;
double total;

I hope this is sufficient information to help figure this out.
Topic archived. No new replies allowed.