MY ASSIGNMENT: Write a program that works with fractions. Your program should be able to add, subtract, multiply, and divide two fractions. Specifically, your program must request two fractions from the user, getting the numerator and denominator separately for each fraction, and the operation to perform (add, subtract, multiply, or divide). Your program will then compute the resulting fraction, keeping the numerator and denominator separate, and output the result. The resulting fraction must be simplified. For example, (4 / 6) should be displayed as (2 / 3), and (8 / 8) should be displayed as (1 / 1). You will need to use the GCD function from Problem 1 to do this simplification, so be sure to test it thoroughly before using it here.
You must compute the resulting fraction using fraction-based math (working with numerators and denominators). Do not simply convert the fractions to double values (like 1.5), do the math, and convert back to a fraction. There are numerous resources on the Internet if you need a refresher on how to add, subtract, multiply, and divide fractions.
This is what I have so far. I kinda need some help on this. Thank You!!
using namespace std;
int fraction_subtract (int x1, int y1, int x2, int y2);
int fraction_add (int x1, int y1, int x2, int y2);
int fraction_multiply (int x1, int y1, int x2, int y2);
int fraction_divide (int x1, int y1, int x2, int y2);
int x1, y1, x2, y2;
cout << "Enter a number for x1 and y1: ";
cin >> x1 >> y1;
cout << "Enter a number for x2 and y2: ";
cin >> x2 >> y2;
int fraction_subtract (int x1, int y1, int x2, int y2)
int denom, num, frac;
denom = y1 * y2;
num = ((x2 * -1) * y1) - ((x1 * -1) * y2);
frac = (num, denom);
What do you need help with? Its best to write out your logic on paper.
For addition you simply multiply the numerators by the opposite fraction's denomiator and multiply the two denomiators together. Your sum is simply an unsimplified fraction with the numerator beginning obviously the sum of the two numerators over the product of the two denom.
Multiplying fractions is self-explaination I hope. Division of fractions is simply multiply a fraction by the reprocial of the fraction your dividing by i.e (1/2)/(1/4) yields the same result as (1/2)* 4 = 2 in this case
Are you not familiar with arthmetic with fractions? The greatest common denom. of any two fractions or any multiple of fractions is the product of the two denomiators. This shouldn't be to hard to see after doing a few problems on paper. However, I don't know how to implement the arthimetic these might help. Also, you did not post a problem, you posted your assignment/homework which no one here will do for you. But looking at it, it doesnt seem your too far off from completion so good job thus far.
now if you were looking for the LCD this would be a different story.
Also to reduce the fraction both the denom. must divide evenly by a term that can be multipled to find the denom. i.e 4/6, 3 * 2 = 6, now do num % any term that created 6 (3 or 2) and do the same from the denom doing num % 2 and denom % 2 , this will return the remainder if it not 0 if did not simplify. Same with the other term, num % 3 and denom % 3 and same case as above. Thats one way you can do it
which will return the value of the remainder in any of the test if the remainder is not