Assignment 4 - Outputting Numbers as Words
You hand in this assignment by showing it to the lecturer when
it is completed. As usual, you first go into the correct directory
(unless you are already there).
cd public_html
Then download this page onto your computer and place it on your webpage.
wget http://www.comp.nus.edu.sg/~gem1501/assignment02.html
chmod 755 *.html
The task is to write a function which outputs the written names of
numbers. So for "0" it should be written "zero" and for "15" it
should be written "fifteen". Furthermore, "101" is
"one hundred and one" and "832" is "eight hundred and thirty two".
The idea is to fill out the functions to be called such that the
correct number is written. Note that there should be an and between
the hundreds and the later digits iff the number is larger than 100
and not a multiple of 100.
The concrete functions to be edited is the function "multipleten"
which currently always returns " twenty". But it should be sensitive
to the input and return " twenty" when d is 2, " thirty" when d is 3,
..., " ninety" when d is 9. Furthermore, some lines of code in the
function "numberwrite" have to be inserted prior to the
comment "COMPLETE HERE" inside the program-text of this function.
The goal is to update the variable "name" accordingly; this can be done
in approximately five lines. You can put together the codes with commands
like
if ((a>0) && (b>1) && (c>0))
{ name = uptotwenty(a)+" hundred and"+multipleten(b)+name; }
and must make sure that each appropriate case is covered. In this example,
the last digit c would already be contained in the variable "name" by
previous commands and therefore text is added to this variable from the
left.
Java Script Starts Here.
Java Script Ends Here.