Thread: C++ program help(converting numbers to english words)

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    1

    Question C++ program help

    I need to write a simple algorithm for converting numbers into english words. The numbers cannot be below -2,000,000,000 or above 2,000,000,000. If anyone can help it would certainly help me a lot.

    Here is what I have so far.
    #include <iostream>
    using namespace std;
    int main ()
    {
    int num;
    cout<<"Enter an integer (or zero to exit)";
    cin>>num;
    while ((num>-2,147,483,647)&&(num<2,147,483,647)){
    if (num>1,000,000,000){
    cout<<num/1,000,000,000;}
    if (num>1,000,000){
    cout<<num/1,000,000;}
    if (num>1,000){
    cout<<num/1,000;}
    if (num>100){
    cout<<num/100;}
    }
    return 0;
    }
    Last edited by bama1; 10-07-2002 at 07:49 PM.

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    Please don't ask people to do all your work for you, See the announcement on Homework at the top of the forum to see what is acceptable ro PM. Basically people are happy to help, but they're not going to do it all for you. Show us what you've got, show your code (using code tags), or where you're confused and someone will be happy to help you I'm sure.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    in my opinion he wasn't asking for a program, but for help. I don't see any need to jump on him unless he came out and said "write my program", but he didn't, he said "any help would be nice" (not exact quote).

    Just my two cents.

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    It sounds like you need an array of string variables... Each string would be one word long and each index-number points a word.

    Because the string itself is an array, you will actually have a two-dimensional array.

  5. #5
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    Do you mean, for instance, that 10023 should be converted into "Ten Thousand twenty three" ?

    If this is the case, you would need to determine what the smallest number of words you would need are, and store them away, in an array (or in a few arrays). For instance, you need the following for sure: "one", "two", "three", "four", ...."twenty", "thirty", etc.
    You don't need things like "twenty one", since it's a combination of two other numbers you already have.

    Notice also that 10023 % 10 is 3, and it would be very convenient if an array index 3 was the word "three". Then if you stored 10023/10, you would be left with 1002, and you could repeat this procedure to get the next array index (2), which might be in another array, where 2 conveniently maps to "twenty". Perhaps you will know that if you are one the first loop iteration, you are in the one's array, and the second loop is the tens array, and the third loop iteration is the hundreds array, Etc., Etc. Just a thought, and I'm not sure if all this works out perfectly, because I really haven't thought it through completely. So there is still some work left for you.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 02-19-2009, 07:19 PM
  2. Replies: 5
    Last Post: 12-21-2007, 01:38 PM
  3. Destinguish between numbers and words
    By Suchy in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2007, 12:48 PM
  4. count words program problem
    By Tony654321 in forum C Programming
    Replies: 8
    Last Post: 10-19-2004, 11:23 AM