Thread: Jumping into C++ chapter 7 help

  1. #1
    Registered User
    Join Date
    Jun 2013

    Jumping into C++ chapter 7 help

    Hello, I'm working through the jumping into C++ beginner ebook and I'm completely stumped on the practice problems for chapter seven. The first one ask to implement source code that will take in numbers between -2billion and 2 billion in number form and print it out in word form (ie 1204 is one thousand two hundred four). These are the steps it says you should do:
    1) Break the number up into chunks of three digits
    2) For each three-digit chunk, compute the text; append the magnitude of that chunk; append the
    chunks together
    3) To compute the text of a three-digit chunk, compute the number of hundreds, and convert that
    one-digit number to text, and add “hundreds”, appending the text of the two-digit chunk
    4) To compute the text of a two-digit chunk, if it’s less than 20, look it up; if it’s greater than 20,
    compute the number of tens, and look up the word, and append the text of the one-digit
    I don't understand how I can seperate the number i input into chunks of three though, can anyone help me understand this? I have gotten a program to work that will give me the numbers 0-19 in word form if I input them just by using a series of 20 different if statements like:
    if (number == 12)
    cout << "The number " << number << " is twelve.";
    but once I start getting into the numbers past nineteen and there are patterns that I can use to efficiently change it into words I am just completely stumped how to implement that... Any help would be appreciated, please let me know if you need anything to be clarified if I didn't make sense.

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Well here's a tip, if you're using integers you can repeatedly do division by 10 and modulus of 10 to get the individual digits of a number. Terminate when the number is less than 10 (obviously)
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #3
    Registered User
    Join Date
    Jun 2012
    Morden, UK
    Can try this thread:

    Maybe this will give you some pointers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Jumping into C++
    By Tamim Ad Dari in forum C++ Programming
    Replies: 4
    Last Post: 01-12-2013, 08:29 PM
  2. Jumping into C++
    By Tamim Ad Dari in forum C++ Programming
    Replies: 9
    Last Post: 01-11-2013, 09:45 AM
  3. Replies: 6
    Last Post: 08-20-2012, 07:09 AM
  4. Jumping into C++ Chapter 5 problem 6 - Critique please
    By Kranky in forum C++ Programming
    Replies: 8
    Last Post: 03-07-2012, 05:44 PM
  5. Jumping to OOP in C++ from C
    By meadhikari in forum C++ Programming
    Replies: 6
    Last Post: 07-16-2010, 05:26 AM