Number Puzzles IV: A New Hope

Use nested for loops to find four positive integers whose sum is 45, and such that the first plus 2, the second minus 2, the third multiplied by 2, and the fourth divided by 2 are all equal.

For those of you having trouble with the English on this one (I've noticed that students really don't like word problems), here's what that means.

The following mathematical statements are also true about these numbers:


Frequently-Asked Questions

I think my code is right, but it doesn't print out anything.
Your loops are probably only letting each number get up to 9. So you are only testing numbers from 0, 0, 0, 0 up to 9, 9, 9, 9, which isn't far enough. (9+9+9+9 is only 36, so they need to able to get bigger if they're going to add up to 45.)

©2013–2016 Graham Mitchell

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.
Creative Commons License