As described in my previous post I will be working through this book and the examples within it, showing the development of my thought process. The idea is to take selected tasks and write my own programs before looking at how the author does it.
Above you can read the task given. In addition to this the author had written that he wants a full number of gumballs rather than a fraction, as they are hard to share. This is why I have used “int”.
After playing around for a short while I came up with the following program, which works and displays the information in a short and concise manor, allowing the user to work through it in a very straightforward fashion.
Above is the version of the author. While I have an extremely limited experience with programming, it feels like he is making the program needlessly complicated as well as the outcome not being particularly user friendly. While it is nice that the answer is encased in a full text, the fact that you are writing two numbers straight after each other following two questions could easily lead to confusion. To top it off his program is also a line longer.
I am happy with my first written program. It felt really good that it was very easy, worked and was even shorter than the author’s example. Needless to say, I look forward to doing more.