Un-reduced Fractions! PLS HELP!!

Hi Guys, I am supposed to write a program which can perform simple fraction arithmetic, however the answer is supposed to come out as an unreduced form.

EG: 3/5 + 1/5 = 20/25

if the result is improper then it can either be a whole number or a mixed number (my choice)

if the problem is un-calculable then an error message is the result.



Below is what I have written so far. I just need to figure out how to get the problem to result in an unreduced form.


Any help would be encouraged. Thank you








#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
int numerator1, numerator2;
int denominator1, denominator2;
int answer1;

cout << "*********** Assignment #7 Section #1003" << endl;
cin >> numerator1;
cin >> denominator1;
cin >> numerator2;
cin >> denominator2;

answer1 = (numerator1 / denominator1) + (numerator2 / denominator2);

cout << numerator1 << "/" << denominator1 << " + " << numerator2 << "/" << denominator2 << " = " << answer1 << endl;

return 0;
}



This is basically the result:

-bash-4.1$ ./a.out *************
************* Assignment #7 Section #1003
3 //input
5 //input
1 //input
5 //input
3/5 + 1/5 = 0 // cout statement.
Answer is int. Int is throwing out everything after the dot(e.g. when result is 25.99345, then result would be just 25). Change it to double.
Also, wrap your code in [.code][./code] tags next time(without dots, of course).

If you want to receive x/y notation, then you shouldn't calculate answer. It won't help you anyway :)

Cheers!
Last edited on
Topic archived. No new replies allowed.