Convert number to words I wrote this converter code. It can convert a number from 1-100 into words. It works perfectly, but it seems to be too complicated to me. 

Can you tell me whether it's okay or not? 

#include &lt;iostream&gt;

int main()
{
    int number;
    int first_digit;
    int second_digit;
    std::cout &lt;&lt; "Enter the number: ";
    std::cin &gt;&gt; number;
    first_digit = number/10;
    second_digit = number%10;
    if(number &gt;= 11 &amp;&amp; number &lt;= 20)
    {
        switch(number)
        {
            case 11:
                std::cout&lt;&lt;"eleven";
                break;

            case 12:
                std::cout&lt;&lt;"twelve";
                break;
            case 13:
                std::cout&lt;&lt;"thirteen";
                break;
            case 14:
                std::cout&lt;&lt;"fourteen";
                break;
            case 15:
                std::cout&lt;&lt;"fifteen";
                break;
            case 16:
                std::cout&lt;&lt;"sixteen";
                break;
            case 17:
                std::cout&lt;&lt;"seventeen";
                break;
            case 18:
                std::cout&lt;&lt;"eighteen";
                break;
            case 19:
                std::cout&lt;&lt;"nineteen";
                break;
        }
    }
    else
    {
        switch(first_digit)
        {
            case 1:
                if(second_digit == 0)
                    std::cout&lt;&lt;"ten";
                break;
            case 2:
                std::cout&lt;&lt;"twenty";
                break;
            case 3:
                std::cout&lt;&lt; "thirty";
                break;
            case 4:
                std::cout&lt;&lt;"fourty";
                break;
            case 5:
                std::cout&lt;&lt;"fifty";
                break;
            case 6:
                std::cout&lt;&lt;"sixty";
                break;
            case 7:
                std::cout&lt;&lt;"seventy";
                break;
            case 8: 
                std::cout &lt;&lt;"eighty";
                break;
            case 9:
                std::cout &lt;&lt;"ninety";
                break;
            case 10:
                std::cout &lt;&lt;"one hundred";
                break;
        }
        if(first_digit &gt; 1 &amp;&amp; number != 100) std::cout&lt;&lt;"-";
        switch(second_digit)
        {
            case 1:
                std::cout&lt;&lt;"one";
                break;
            case 2:
                std::cout&lt;&lt;"two";
                break;
            case 3:
                std::cout&lt;&lt;"three";
                break;
            case 4:
                std::cout&lt;&lt;"four";
                break;
            case 5:
                std::cout&lt;&lt;"five";
                break;
            case 6:
                std::cout&lt;&lt;"six";
                break;
            case 7:
                std::cout&lt;&lt;"seven";
                break;
            case 8:
                std::cout&lt;&lt;"eight";
                break;
            case 9:
                std::cout&lt;&lt;"nine";
                break;
            default:
                break;

        }
    }
    return 0;
}
I've never tackled such a problem before, so I'll proceed with this cautiously.


You don't need to declare those three variables and then assign to them.  Instead, initialize them right away where they're first used.

You can also move number right above the cin for slightly closer scope.

std::cout &lt;&lt; "Enter the number: ";
int number;
std::cin &gt;&gt; number;
int first_digit = number/10;
int second_digit = number%10;

I suppose switch is an okay choice for this program.  Either way, the switch can still be condensed while making the program more modular (with functions).

Here's what 11-20 could look like within its own function:

std::string elevenThroughTwenty(unsigned int number)
{
    switch (number)
    {
        case 11: return "eleven";
        // ...
        case 20: return "twenty"; // you forgot the 20 in your code

        // throw an exception if number not in the switch
        // include &lt;stdexcept&gt; to use this
        default: throw std::logic_error("Not 11 through 20");
    }
}


Separating them as such helps with readability, organization, and conciseness.  You will also need proper defaults so that invalid numbers don't cause crippling errors.