Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Liutauras Vilda
• Junilu Lacar
Sheriffs:
• Tim Cooke
• Jeanne Boyarsky
• Knute Snortum
Saloon Keepers:
• Stephan van Hulst
• Tim Moores
• Tim Holloway
• Carey Brown
• Piet Souris
Bartenders:
• salvin francis
• fred rosenberger
• Frits Walraven

# Assignment 1.4

Ranch Hand
Posts: 18944
I've just done assignment 1.4 and it works correctly with two methods. The first one is for numbers less than twenty or divisible by ten and the second is for the other numbers under 99 (this is so that you don't end up with a hyphen in numbers such as 50). I'm now looking at extending this for larger numbers. Is there an obvious step to take to do all numbers up to 999,999,999,999 or is it better to try to do it in stages eg get numbers up to 999, then 999,999 etc. I know that others will have done it in completely different ways to me but maybe what I have done will sound familiar to someone

Ranch Hand
Posts: 31
As you suggested, there are several approaches to this assignment. I am still working on my third submission, and will probably have more. Paul Wheaton made a good suggestion in another message that really helped me.
He said...

For some cattle drive folks I add the requirement that I want them to make a method that introduces some abstraction. The method will take and integer and the value must be in the range of 0 to 999. It will then "say" that value.
If you have such a method, writing your main becomes much easier. From within this new method, your task becomes much easier. The whole program falls together.

He's right, once you have done this the program seems to be much easier to write and you can easily add other methods to handle the larger numbers.
One other side note, don't forget about negative numbers!
Brian

Ranch Hand
Posts: 424
In the assignment I can not see any thing about negative numbers,
doing so means: ignore KISS -principle?!
So my solution will definitely not include negative numbers, the change is not worthwile to include (imho=in my humble opinion).

Sheriff
Posts: 9099
12
"... read in a number from 0 to 99 .... The program must also report any values that are out of range."

Your program must tell the user if they put in a number out of the range of 0 to 99.

 "Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter https://coderanch.com/t/730700/ScroogeXHTML-RTF-HTML-XHTML-converter