Thread: C++: Converting Numeric String to Alpha String

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    1

    C++: Converting Numeric String to Alpha String

    I am attempting to write code that will convert a Numeric (Currency) String to an Alpha String. The program receives a currency value input from the user and I want the program to display the Alpha representation for that value.

    Example:

    User inputs "500". The program converts it to and displays it as "$500.00". I want the program to also display the Alpha representation "Five Hundred Dollars".

    Thank you for your help.
    -JosephCardsFan

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    What have you tried so far? You'll find that we aren't very helpful if all you've done to solve the problem is sit and stare blankly at your monitor before posting this thread.
    My best code is written with the delete key.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    1: Concatenate strings. strcat(), or if you use std::string's there is an overloaded + operator. It only works for strings and chars though. To concatenate other types use an std::stringstream.

    2: Traverse the string version of the number (or use modulus) to get each induvidual digit. Then use some table-lookup to convert it.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    You could always go the hard route of using locales and the money_put facet. Good luck trying to get that to work.

    Messing around with strings is probably easier for you at this point.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  3. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  4. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM