posted 9 years ago
He can't edit the post after a reply; I went back and did it for him.
That code looks as if you are guessing. You can guess 1000000 times and (if all the guesses are different) there is a good chance you will get a working solution. I thought the first attempt at the loop was better except you never reduced anything. Or you can work it out and get it to work first time.
What you are doing now is dividing. That is one way to work out how many widths you need, but not in a loop. A 12′ wide wall will take 5 widths if they are 2′ 6″ wide. To get that into integer arithmetic, change it all to inches. 144 ÷ 30 is 4 in integer arithmetic, remainder 24, so you need 5 widths.
You can work out the loop more easily if you have three variables: width of wall, width of paper and wall remaining. I presume you are counting widths and parts of widths.