Feature #4: Fare in Words
Implementing the "Fare in Words" feature for our "Uber" project.
We'll cover the following...
Description
At the end of a ride, the Uber app displays the fare to the customer. For accessibility, we want the fare to be read out, should the customer so choose. Assuming that the ride fare is an integer and that a text to speech engine is available, all we need to do is to convert the fare to English words. For example, we need to change $120 to one hundred and twenty dollars. The fare may be as high as several billion depending on the country the ride is taken in.
We’ll be provided with an integer number, fare
, which represents the fare. Our task will be to convert fare to its English word representation.
Solution
We can solve this problem by dividing the initial number into a specific set of digits and then solving those sets. Initially, we can split the number into sets of three. For example, if we split the amount 1234567890
into ...