Hey I'm working on a code where I have to use the grow method to double the size of an existing rectangle. my first rectangle is Rectangle recOne = new Rectangle(10, 15, 5, 8); as you can see my width is 5 and height is 8. I further proceeded to do this : recOne.grow(5, 4); since the grow method is (width + 2h, heigth + 2v) The result I'm receiving for the new rectanlge is (9, 16) and not (10, 16). A friend of mine who is more advanced in coding told me this had to do with integer division.
sorry that's recOne.grow(5/2, 4)
5 / 2 in integer division equals 2. Any fraction is truncated (cut off). The plus side to this is that 5 % 2 = 1, the modulus ( remainder ) is one.
If you are using C++ you might just add decimal points to your elements and deal with float datatypes..
Join our real-time social learning platform and learn together with your friends!