fraction addition ,subtaction, muiltiplication and division

The program im working on needs takes in user input like this:

Enter Problem: 1/8 + 4/8


and outputs it like this

result: 5/8

How do you make the fraction output like that. How do you format it that way? Another question is how would I break down the user input the "/" in the input confuses me .

P.S I need to use functions
1) you need to analyze string and find numbers in it.
2) you need to find dividend and divisor
3) to do calculations by fraction rules. http://en.wikipedia.org/wiki/Fraction_%28mathematics%29
4) return string "result"
Last edited on
i remember doing this a while back without strings. its something like
std::cin << anumber << a char << anumber1;
than some statement/set of statements to call upon functions that will do the calculation.
cin method will work but only if you use '>>' insertion operator rather than '<<' extraction operator....

+

u can also do it c functions;
-> scanf()
-> printf()

if u want to use functions!
Whoops. Used to my compiler doing the operator for me. Same concept though.
so to get the user input i should use this code

cin>>num1>>char1>>denum1>>char 2>>num2>>char3>>denum2;


num1= numerator
char1= "/" the division
denum1 = denominator

char 2= " " it ould be *,/,+,-

num 2 = numerator 2
char3 = /
denum 2 = denominator 2
in theory yes, cin ignores whitespace so that should work.
Topic archived. No new replies allowed.