Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Converting a numeric date to written english

Posted on 2002-03-22
4
Medium Priority
?
323 Views
Last Modified: 2010-04-02
Hey guys, I am writing a program that will accept a date in the MM/DD/YYYY format and return it in written english...EX: March Fifth, Two Thousand Two

I have the program working from 1990 through now, including filtering out erroneous dates...such as the 29th of February on a non-leap year.  So far I have been converting everything through a CASE SWITCH statement

EX:  CASE 1990: return "nineteen-ninety";

Here's the problem...I want this program to perform this function at least back to 1900...or earlier would be better.  I cannot figure out a way to write these year statements without typing out every single year that I want to have available.  What would be a good way of going about this?

Thanks in advance,

Jeff
0
Comment
Question by:96gtjeff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 6890375
You could just make a string for each two digit number from 0 to 19.
Then use a dual algrithm to come up with the numbers from 20 to 99
0
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 400 total points
ID: 6890509
First, you need to define some constant "roots" (or you may say elements) for each digit except 0.

1: one
2: two, twen (<- twenty)
3: three, thir (<- thirteen, thirty)
4: four, for (<-forty)
5: five, fif (<-fifty, fifteen)
6: six
7: seven,
8: eight, eigh (<- eighty, eighteen)
9: nine
10: ten
1000: thousand
10+a (2<a<10): teen
10*a (1<a<10): ty

The parathesis with <- is/are the cases where the "root" is used.

Next, define some constant strings for the following exceptional cases:
00: hundred
11: eleven
12: twelve

Then you need to define some rules (where y=input year, and the content inside parenthesis is just for human explanation only, not for coding):

=====================================================
Case A)
y/100==19 (=> 9 + 10)
=> "nine" + "teen"; n=y-1900;

n==0 (=> 00)
=> "-hundred"
0<n<13 => + "-and-" + (direct translation of n)
13<=n<=19 => "-" + (translation of n-10) + (direct translation of (10+a))
2<=n<=9 && n%10==0 => "-" + (translation of n/10) + (direct translation of (10*a))
2<=n<=9 && n%10!=0 => "-" + (translation of n/10) + (direct translation of (10*a)) + "-" + (direct translation of n%10)
=====================================================
Case B)
y>=2000 (=> 2 * 1000)
=> "two" + "-" + "thosand" + "-" + "and-"; n=y-2000;
0<n<13 => + (direct translation of n)
13<=n<=19 => (translation of n-10) + (direct translation of (10+a))
2<=n<=9 && n%10==0 => (translation of n/10) + (direct translation of (10*a))
2<=n<=9 && n%10!=0 => (translation of n/10) + (direct translation of (10*a)) + "-" + (direct translation of n%10)
=====================================================

This is just a pseudocode. You need to translate to
C++ using conditionals.
0
 

Author Comment

by:96gtjeff
ID: 6890513
Thank you very much...this oughta do it.
0
 
LVL 84

Expert Comment

by:ozo
ID: 6890517
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question