I'm trying to write a program that uses rational numbers (entered as a whole numerator and a whole denominator). Eventually I want it to add/subtract/multiply/divide rational numbers but for now I'm trying to get it to add two rational numbers. Ignore the green part of the code. Could someone please explain to me why my add function doesn't work?
Could someone please explain to me why my add function doesn't work? (followed by 137 lines of code)
From Welcome -- read before posting
Don't ask others to debug your broken code without giving a hint what sort of problem they should be searching for. Posting a few hundred lines of code, saying "it doesn't work", will get you ignored. Posting a dozen lines of code, saying "after line 7 I was expecting to see <x>, but <y> occurred instead" is much more likely to get you a response.
I copied your code and built it. My IDE (xcode) gave one warning: "Control reaches end of non-void function" on line 129.
Try that... Also, where are your constructors? If you allow your constructor to take an int (or short) you could avoid the overloaded functions. Also, consider passing your rational numbers around as references in the method's parameters. And why use the name "add" when you could use "operator+"...?