Re: Converting Numbers to Words in English by recursion.
- From: Randy Howard <randyhoward@xxxxxxxxxxxxxxxxx>
- Date: Sat, 10 Mar 2007 08:43:47 GMT
On Sat, 10 Mar 2007 02:07:39 -0600, Richard Heathfield wrote
(in article <dqadnTh4WpCZ-m_YnZ2dnUVZ8vmdnZ2d@xxxxxx>):
Phlip said:
jedale wrote
I am trying to convert numbers to there corresponding words but it
only works for numbers under 1,000 but need it to work for 1 billion.
Where are your unit tests?
I would use C++,
Well, that's up to you. :-) Not everyone shares your enthusiasm for
that language.
and would start like this:
assert("zero" == convert(0));
Then I would write convert like this:
string
convert(int x)
{
return "0";
}
Then I would assert for "one" == convert(1), and change the code to
say if(x == 1) return "one".
That sounds silly,
Yes, it does.
but it isn't.
Yes, it is.
That's because the end-game of any form of zealotry is silliness.
At the time you have 2, you should
refactor the convert function into a little lookup table.
A lookup table is an inadequate solution here. Why bother to code an
inadequate solution? And you've completely ignored the spec, too.
It's okay as long as you have unit tests, apparently.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw
.
- References:
- Converting Numbers to Words in English by recursion.
- From: jedale
- Re: Converting Numbers to Words in English by recursion.
- From: Phlip
- Re: Converting Numbers to Words in English by recursion.
- From: Richard Heathfield
- Converting Numbers to Words in English by recursion.
- Prev by Date: Re: how to test this piece of C code
- Next by Date: Re: how to test this piece of C code
- Previous by thread: Re: Converting Numbers to Words in English by recursion.
- Next by thread: Re: Converting Numbers to Words in English by recursion.
- Index(es):
Relevant Pages
|