In my program I am using a class called Fraction and having the user input a numerator and a denominator and the solving the fraction and then the fraction gets reduced to lowest terms and printed. I am having trouble figuring out how to get the fraction to reduce and then print. This would go in the void Fraction::setFractReduce() function.
What do you have so far for the function? If we can see what you have we can push you in the right direction.
Also something I noticed doing a quick scan of the code you posted is this.
You declare a object of you class in every member function... Why? you don't need them there delete them. I think you are doing this so you can use the private variables of the class? If so you don't need to do that, every member function has access to the private variable of its class.
See that is where I am stuck. I am not sure how to start this function. I have seen some examples with bool functions but it does not go well to use double values with the % sign I guess.
And I understand about the declaring the object of my class in every function, it was habit but I understand that I do not need it there. Thank you.
I suck at fractorials and specially decimal ones but here is a one that uses int's and solves your problem with recursion (Which is probably not the best way to go about it) maybe it can give you some ideas.
1 2 3 4 5 6 7
int Fraction::setFractReduce(int n,int d)
{
if (d != 0)
setFractReduce(d , n % d); //recursive call
return n; //return n when d equals 0
}
How can I get a do while loop to work for this program? At the end i want it to ask the user if they want to find another fraction answer but I am not sure how? any hints?
bruntmjust (115) Mar 12, 2013 at 12:59am
So I am a beginner and was wondering
@cire what does std::ostream& operator<<(std::ostream& os, const MyFraction & f ) mean? What is going on here?
@thejman250 Your suggestions were very helpful!! Thank you very much, those options are good.
@Zereo Thank you for that example it does give me a lot of ideas, I appreciate you helping out.
bruntmjust wrote:
I figured out the do while loop. Thank you everyone for your help on this. Things make a lot more sense now. Thank you again!!!