Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6846877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:40:36+00:00 2026-05-27T00:40:36+00:00

I am new to programming and especially C++ so I decided to re-write a

  • 0

I am new to programming and especially C++ so I decided to re-write a java program I wrote to convert a number (for example 13) to words (thirteen), and it worked fine but I tried re-writing it in C++ and after compiling, starting the program, and entering the number it does nothing. I am sorry if thing like my variable’s names are unusual.

This is the java program:

public class Say
{
//AAAARRRRRR!!!! Here be Arrrrrrays!
static String first[] =
{
    "" , "One " , "Two " , "Three ", "Four ", "Five " , "Six " , 
    "Seven " , "Eight " , "Nine " , "Ten " , "Eleven " , "Twelve " , 
    "Thirteen " , "Fourteen " , "Fifteen " , "Sixteen " , "Seventeen " ,
    "Eighteen " , "Nineteen "
};

static String second[] =
{
    "" , "" , "Twenty " , "Thirty " , "Fourty " , "Fifty " , 
    "Sixty ", "Seventy " , "Eighty " , "Ninety "
};

static String sections[] =
{
    "" , "Hundred " , "Thousand " , "Million " , "Billion "
};
//Number stuff ho!
public static void main( String[] args )
{
    String origin = ( args[0] );
    int original = Integer.parseInt( origin );
    int orlength = origin.length();
    int remaindr = ( orlength % 3 );
    int legroups;
    if ( remaindr != 0 )
    {
        legroups = ( orlength / 3 + 1 );
    }
    else
    {
        legroups = ( orlength / 3 );
    }

    //Groups AAAARRR here matey!
    int groupone = ( original % 1000 );
    int grouptwo = ( ( ( original % 1000000 ) - groupone ) / 1000 );
    int groupthr = ( ( ( original % 1000000000 ) - grouptwo ) / 1000000 );



    //[Pirate themed comment on this being a loop]
    boolean finished = false;
    int takestep = 0;
    while ( finished == false )
    {
        takestep ++;
        int numinact;
        if ( takestep == 1 )
        {
            numinact = groupthr;
        }
        else if ( takestep == 2 )
        {
            if ( groupthr != 0 )
            {
                System.out.print( sections[ 3 ] );
            }
            numinact = grouptwo;
        }
        else
        {
            if ( grouptwo != 0 )
            {
                System.out.print( sections[ 2 ] );
            }
            numinact = groupone;
            finished = true;
        }
        if ( numinact > 99 )
        {
            int hundreds = ( ( numinact - ( numinact % 100 ) ) / 100 );
            System.out.print( first [ hundreds ] + sections [ 1 ] );
            numinact = ( numinact % 100 );
        }
        if ( numinact <= 19 )
        {
            System.out.print( first [ numinact ] );
        }
        else if ( numinact <= 29 )
        {
            int digitact = ( numinact - 20 );
            System.out.print( second[ 2 ] + first[ digitact ] );
        }
        else if ( numinact <= 39 )
        {
            int digitact = ( numinact - 30 );
            System.out.print( second[ 3 ] + first[ digitact ] );
        }
        else if ( numinact <= 49 )
        {
            int digitact = ( numinact - 40 );
            System.out.print( second[ 4 ] + first[ digitact ] );
        }
        else if ( numinact <= 59 )
        {
            int digitact = ( numinact - 50 );
            System.out.print( second[ 5 ] + first[ digitact ] );
        }
        else if ( numinact <= 69 )
        {
            int digitact = ( numinact - 60 );
            System.out.print( second[ 6 ] + first[ digitact ] );
        }
        else if ( numinact <= 79 )
        {
            int digitact = ( numinact - 70 );
            System.out.print( second[ 7 ] + first[ digitact ] );
        }
        else if ( numinact <= 89 )
        {
            int digitact = ( numinact - 80 );
            System.out.print( second[ 8 ] + first[ digitact ] );
        }
        else if ( numinact <= 99 )
        {
            int digitact = ( numinact - 90 );
            System.out.print( second[ 9 ] + first[ digitact ] );
        }
    }       
    //Yarrr! Debug be what this is!
    //System.out.println( " original is " + original + ", orlength is " +
    //  orlength + ", remaindr is " + remaindr + ", legroups is " + 
    //  legroups + ", groupone is " + groupone + ", grouptwo is " +
    //  grouptwo + ", groupthr is " + groupthr );
}

}

And this is the C++ re-write that does not work:

//C++ port of the Say.java program.
//I hope to extend to longer numbers in the future.

#include <iostream>
#include <string>

using namespace std;

static string digit [20] =
{
"" , "One " , "Two " , "Three ", "Four ", "Five " , "Six " , "Seven " , 
"Eight " , "Nine " , "Ten " , "Eleven " , "Twelve " , "Thirteen " , 
"Fourteen " , "Fifteen " , "Sixteen " , "Seventeen " , "Eighteen " ,
"Nineteen "
};

int main()
{
int original;   //declare int
cout << "Enter your number: ";  //Requests user input
cin >> original;    //Recieves user input assigns value to previous variable
//Groups of 3 digits
int groupone = ( original % 1000 );
int grouptwo = ( ( original / 1000 ) % 1000);
int groupthr = ( original / 1000000 );

//Intense loop, almost direct from java version.

bool finished = false;
int takestep = 0;
while ( finished != true );
{
    takestep ++;
    int numinact;
    if ( takestep == 1 )
    {
        numinact = groupthr;
    }
    else if ( takestep == 2 )
    {
        if ( groupthr != 0 )
        {
            cout << "Million ";
        }
        numinact = grouptwo;
    }
    else
    {
        if ( grouptwo != 0 )
        {
            cout << "Thousand ";
        }
        numinact = groupone;
        finished = true;
    }
    if ( numinact > 99 )
    {
        int hundreds = ( ( numinact - (numinact % 100 ) ) / 100 );
        cout << digit[ hundreds ] << "Hundred ";
        numinact = ( numinact % 100 );
    }
    if ( numinact <= 19 )
    {
        cout << digit[ numinact ];
    }
    else if ( numinact <= 29 )
    {
        int digitact = ( numinact - 20 );
        cout << "twenty " << digit[ digitact ];
    }
    else if ( numinact <= 39 )
    {
        int digitact = ( numinact - 30 );
        cout << "thirty " << digit[ digitact ];
    }
    else if ( numinact <= 49 )
    {
        int digitact = ( numinact - 40 );
        cout << "fourty " << digit[ digitact ];
    }
    else if ( numinact <= 59 )
    {
        int digitact = ( numinact - 50 );
        cout << "fifty " << digit[ digitact ];
    }
    else if ( numinact <= 69 )
    {
        int digitact = ( numinact - 60 );
        cout << "sixty " << digit[ digitact ];
    }
    else if ( numinact <= 79 )
    {
        int digitact = ( numinact - 70 );
        cout << "seventy " << digit[ digitact ];
    }
    else if ( numinact <= 89 )
    {
        int digitact = ( numinact - 80 );
        cout << "eighty " << digit[ digitact ];
    }
    else if ( numinact <= 99 )
    {
        int digitact = ( numinact - 90 );
        cout << "ninety " << digit[ digitact ];
    }
}
return 0;
}

What must I change to get it to run like the java program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:40:37+00:00Added an answer on May 27, 2026 at 12:40 am

    This does not do what you think it does:

    bool finished = false;
    while ( finished != true );
    {
        // blah blah blah
        finished = true;
    }
    

    The semicolon at the end of that while line makes it an infinite loop followed by a block which you never reach (because of that infinite loop).

    Remove the semicolon and you will get:

    pax$ ./testprog
    Enter your number: 1234
    One Thousand Two Hundred thirty Four
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to programming and especially to Java... So it takes me
First off, I am new to programming (especially with C#) and thanks for your
I'm new to programming and especially C++ which I'm keen to learn, although out
First off, a lil about me, i'm very new to GUI programming, especially with
I am new to programming especially jQuery and webservices. I want to pass the
I am new to programming especially jQuery. I am trying to use ColorBox to
I am new to programming especially jQuery. I am trying to sort (order) images
I can still be considered 'new' to web development and server-side programming especially. I
I am new with Android programming and especially with PayPal. I got an application
I'm currently new into client-side programming, especially using the Jquery Ajax method to call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.