home *** CD-ROM | disk | FTP | other *** search
- /* engint.c - convert an int to its English equivalent */
- /* Version 1.1 1982/11/14 21:56 */
-
- /*
- Copyright 1982 William G. Hutchison, Jr.
- P.O. Box 278
- Exton, PA 19341-0278
- USA
-
- CompuServe 70665,1307
-
-
- This program may be used freely for any non-commercial
- purpose, provided that the user does not remove or alter
- this notice or the copyright statement.
- Those who wish to sell or lease this program, or to
- incorporate it into a product for sale or lease, should
- apply to the author (above) for licensing information.
- This program is not covered by a warranty, either
- express or implied. The author shall not be responsible for
- any damages (including consequential) caused by reliance on
- the materials presented, including but not limited to
- typographical errors or arithmetic errors.
-
- */
-
- #ifdef MAINLY
- #else
- #include "c80def.h"
- #endif
- #ifdef CP_M
- extern FILE *STDIN, *STDOUT;
- #endif
- #undef trace
- #ifdef trace
- #include printf.c
- #endif
-
- char *tens[]= {
- "twenty", "thirty", "forty", "fifty",
- "sixty", "seventy", "eighty", "ninety"};
- char *teens[]= {
- "zero", "one", "two", "three", "four",
- "five", "six", "seven", "eight", "nine",
- "ten", "eleven", "twelve", "thirteen",
- "fourteen", "fifteen", "sixteen",
- "seventeen", "eighteen", "nineteen"};
-
-
- engint(n) /* convert n to English in ASCII */
- int n;
- {
- _engint(n, 0);
- }
-
- _engint(n, L) /* convert n to English in ASCII */
- int n;
- int L /* depth of recursion */;
- {
- int LL /* new depth of recursion */;
-
- #ifdef trace
- printf("\nn=%7d, level=%7d\n", n, L);
- #endif
- LL= L+1;
- if (n <= -1000 || n >= 1000) {
- _engint(n/1000, LL);
- fputs(" thousand",STDOUT);
- _engint(abs(n % 1000),LL);
- }
- else if (n < 0) {
- fputs(" minus",STDOUT);
- _engint(-n, LL);
- }
- else if (n >= 100) {
- _engint(n/100, LL);
- fputs(" hundred",STDOUT);
- _engint(n % 100, LL);
- }
- else if (n >= 20) {
- fputs(" ",STDOUT);
- fputs(tens[n/10-2],STDOUT);
- _engint(n%10,LL);
- }
- else if (n > 0 || L == 0) {
- fputs(" ",STDOUT);
- fputs(teens[n],STDOUT);
- }
- } /* end _engint */
-
- #ifdef MAINLY
- #else
- /* test driver for engint */
- #ifdef trace
- #else
- #include "printf.c"
- #endif
- #define MAINLY
- #include "puts.c"
- #include "randi1.c"
- main() {
- int n;
- register int seed;
- for (n=0; n <= 1000; n++) {
- printf("%7d", n);
- engint(n);
- printf("\n");
- printf("%7d", -n);
- engint(-n);
- printf("\n");
- }
- for (n= -32768; n < 0; ) {
- printf("%7d", n);
- engint(n);
- printf("\n");
- printf("%7d", -n);
- engint(-n);
- printf("\n");
- if (n < -1000)
- n+= randi1(&seed)%100;
- else
- n++;
- }
- } /* end main */
-
- abs(n){return(n<0? -n:n);}
- #endif