If anyone could help me. This program is to compute the harmonic number in fraction form of the number entered by the user. I have set up the operator overload for the + to add two fractions together. In my main i have the newf + newf1. I am trying to figure out how I can put that result stored in something so i can add the next lowest fraction. For example if i put in 3 for the input i want to add newt which equals 1/3 then newf which equals 1/2. This result is 5/6. So i need to be able to store 5/6 and then add the next fraction in the harmonic number sequence which is 1/1.
Yes i do still have to call reduce, but at the current point i still need to add the last value of 1/1 so i need to store the current value of 5/6. So the current value of (newf+newf1);
is 5/6. But the harmonic number of 3 should be 11/6 or (5*1)+(6*1) for the numerator; and then 6*1 for the denominator.
I cant figure out how to store the result of (newf+newf1); so i can add the next value.
Harmonic number of 3. 1/1 +1/2 +1/3=11/6
Lines 33, 34, 40, 47, 54, and 82 do nothing sensible.
Lines 87 and 89 lead to data=0, which is not the greatest of denominators.
The result of evaluating line 93 is not stored.
You will get big values. You should use the greatest common divisor to simplify your fractions.
Standard library provides a template op!= that works if you have op== so you don't need to define both (or the implementation of (a!=b) should be a simple !(a==b)
You probably want op< too.
Have you thought about the assignment (+=, -=, *=, /=) versions of operators?
I have GCD function that will be implemented under reduce.
The result of line 93 is exactly what i want to store but i am drawing a massive blank on how to do so.
I want to put something like fraction newf2=(newf+newf1)
But that doesn't seem to work.
Once i get that result stored i can then complete the calculation and then implement the GCD to reduce the fraction.
**GCD is greatest common divisor.
you know sometimes when someone gives you the simplest of answers that i should already know i feel like a massive idiot. it works just like it should. Thank You kesiverto.