Issue with converting numerical values to string elements
<p>So as the title implies I am having an issue with my algorithm used to convert numerical values to strings.  I can get up to a certain amount but then the program crashes once I hit 100 dollars.  I'm also off by a couple cents on some values so I'm wondering what I could do to change that as well. </p>

<p>Here is my header file</p>

<pre><code>#include &lt;sstream&gt;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;string&gt;
#include &lt;string.h&gt;
using namespace std;

class TextVersionOfNumber
{
private:
    double amount;
public:
    string getTextVersionOfNumber();
    void setAmount(double);
};
</code></pre>

<p>Here is my .cpp file (this is where the algorithm is)</p>

<pre><code>#include "TextVersionOfNumber.h"


string TextVersionOfNumber::getTextVersionOfNumber()
{
    string upto20[20] = { "", "one", "two", "three", "four",
        "five", "six", "seven", "eight", "nine", "ten",
        "eleven", "twelve",
        "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
        "eighteen", "nineteen" };

    string ten_ninety[10] = { "", "", "twenty", "thirty", "forty",
        "fifty", "sixty", "seventy", "eighty", "ninety" };

    double _amount1 = (int)amount;
    double _amount2 = (amount - _amount1) * 100;

    string str_one = "";

    if (_amount1 &lt;= 19)
    {
        str_one = upto20[(int)_amount1];
    }
    else
    {
        int tens = _amount1 / 10;
        int ones = _amount1 - (tens * 10);
        str_one = ten_ninety[tens] + upto20[ones];
    }

    string str_two = "";

    if (_amount2 &lt;= 19)
    {
        str_two = upto20[(int)_amount2];
    }
    else
    {
        int tens = _amount2 / 10;
        int ones = _amount2 - (tens * 10);
        str_two = ten_ninety[tens] + upto20[ones];
    }

    string ret_val = "$ " +str_one + " and " + str_two + " cents";
    system("pause");
    return ret_val;
};



void TextVersionOfNumber::setAmount(double _amount)
{
    amount = _amount;
};
</code></pre>

<p>And here is the tester file (this was provided by my teacher)</p>

<pre><code>//  Chapter 12--  Assignment 14:  Check Writer
// This program can convert a dollar and cents amount given in 
// numerical form to a word description of the amount.
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;string&gt;
#include &lt;string.h&gt;
using namespace std;

#include "TextVersionOfNumber.h"
// Assume a maximum amount of $10,000

int main()
{
    string date = "03/05/2016", payee = "Michael Wille";
    TextVersionOfNumber checkAmount;
    double testAmounts[] = { 0, .01, .25, 12, 12.45, 19, 19.02,
        19.45, 20, 20.45,
        34, 56.78, 100, 109, 119.78,
        450, 678.90, 1000, 1009.45, 1056,
        1234, 1567.98, 9999, 9999.99 };

    for (int i = 0; i &lt; sizeof(testAmounts) / sizeof(double); i++)
    {
        double an_amount = testAmounts[i];
        checkAmount.setAmount(an_amount);
        cout &lt;&lt; setprecision(2) &lt;&lt; fixed;
        cout &lt;&lt; setw(60) &lt;&lt; right;
        cout &lt;&lt; "Date: " &lt;&lt; date &lt;&lt; endl;
        cout &lt;&lt; "Pay to the order of:  " &lt;&lt; payee &lt;&lt; "\t\t\t";
        cout &lt;&lt; "$" &lt;&lt; an_amount &lt;&lt; endl;
        cout &lt;&lt; checkAmount.getTextVersionOfNumber() &lt;&lt; endl;
        cout &lt;&lt; "---------------------------------------------------------------------\n";
    }
    system("pause");
    return 0;
}
</code></pre>