# Check writer \[C++\]-Help please!

**URL:** <https://forum.freecodecamp.org/t/check-writer-c-help-please/63841>\
**Category:** General\
**Created:** [December 10, 2016, 6:08am UTC](https://forum.freecodecamp.org/t/check-writer-c-help-please/63841 "2016-12-10T06:08:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![clopez0201](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@clopez0201](https://forum.freecodecamp.org/u/clopez0201)\
**Post date:** [December 10, 2016, 6:08am UTC](https://forum.freecodecamp.org/t/check-writer-c-help-please/63841/1 "2016-12-10T06:08:55Z")

</div>

Hello I am having trouble having my program print out from integers to string in order to display a written form of the number. Here is what my files look like.

This is my class tester .cpp file (NO changes needed)

```auto
#include <iostream>  
#include <iomanip>
#include <string>
#include <string.h>
#include <sstream>
#include "TextVersionOfNumber.h"
using namespace std;
// Assume a maximum amount of $10,000

int main()
{
	string date = "03/07/2013", payee = "Greg Dunkin";
	TextVersionOfNumber checkAmount;
	double testAmounts[] = { 0, .01, .25, 12.12, 12.45, 19, 19.02,
		19.45, 20, 20.65,
		34, 56.78, 100.21, 109.05, 119.78,
		450, 678.90, 1000, 1009.45, 1056,
		1234.15, 1567.98,9999, 9999.99 };
	cout << setprecision(2) << fixed;

	for (int i = 0; i < sizeof(testAmounts) / sizeof(double); i++)
	{
		double an_amount = testAmounts[i];
		checkAmount.setAmount(an_amount);

		cout << setprecision(2) << fixed;
		cout << setw(60) << right;
		cout << "Date: " << date << endl;
		cout << "Pay to the order of: " << payee << "\t\t\t";
		cout << "$" << an_amount << endl;
		cout << checkAmount.getTextVersionOfNumber() << endl;
		cout << "--------------------------------------------\n";
	}
	return 0;
}

```

This is my class header file (.h)

```auto
#pragma once
#include <iostream> //std::cout
#include <iomanip>
#include <string> //std::string
#include <sstream> //std:;stringstream
#include <string.h>
using namespace std;
class TextVersionOfNumber
{
private:
	double amount;
public:
	string getTextVersionOfNumber();
	void setAmount(double);
};

```

And this is my class .cpp file

```auto
#include <iostream>
#include <string>
#include <iomanip>
#include <string.h>
#include <sstream>
#include "TextVersionOfNumber.h"
using namespace std;

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

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

	int thousand = amount / 1000;
	int hundred = (amount - thousand * 1000) / 100;
	int tens = ((amount - (thousand * 1000 + hundred * 100)) / 10);
	int ones = (amount - (thousand * 1000 + hundred * 100)) - tens * 10;
	int cents_tens = (amount - (thousand * 1000 + hundred * 100) - tens * 10 - ones) * 10;
	int cents_ones = (amount - (thousand * 1000 + hundred * 100) - tens * 10 - ones) * 100 - cents_tens * 10;

	if (amount < 1.0)
		cout << "zero dollars and " << twenty_90[cents_tens] << one_19[cents_ones] << " cents.\n";
	else if (amount < 20)
		cout << one_19[ones] << "dollar and " << twenty_90[cents_tens] << "-" << one_19[cents_ones];
	else if (amount <100)
	{
		cout << twenty_90[tens] << "-" << one_19[ones] << "dollars and " << twenty_90[cents_tens] << "-" << one_19[cents_ones] << " cents.";
	}
	else if (amount < 1000)
	{
		cout << one_19[hundred] << "hundred and" << twenty_90[tens] << "-" << one_19[ones] << " dollars and " << twenty_90[cents_tens] << "-" << one_19[cents_ones] << " cents. ";

	}
	else if (amount < 10000)
	{
		cout << one_19[thousand] << "thousand " << one_19[hundred] << "hundred and" << twenty_90[tens] << "-" << one_19[ones] << " dollars and " << twenty_90[cents_tens] << "-" << one_19[cents_ones] << " cents. ";
	}
	else;
	return 0;
}
void TextVersionOfNumber::setAmount(double _set_amount)
{
	amount = _set_amount;
}

```

I keep recieving an error message but not sure what is wrong.

---

<div class="post-metadata">

**Author:** ![pnahratow](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pnahratow/32/164104_2.png) [@pnahratow](https://forum.freecodecamp.org/u/pnahratow)\
**Post date:** [December 10, 2016, 8:57am UTC](https://forum.freecodecamp.org/t/check-writer-c-help-please/63841/2 "2016-12-10T08:57:04Z")

</div>

Your declared your method `string getTextVersionOfNumber();` to return a string.  
At the end of it you `return 0` and it tries to construct a string from the number 0.

Which the first link when searching for your error message hints at:

[http://stackoverflow.com/questions/11705886/how-to-avoid-the-error-terminate-called-after-throwing-an-instance-of-stdlog](http://stackoverflow.com/questions/11705886/how-to-avoid-the-error-terminate-called-after-throwing-an-instance-of-stdlog)

Some generic hints for your journey

- Learn to use breakpoints and the debugger early on. It helps immensly when looking for bugs you don’t immediately see.
- Always post your error message when asking for help

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 6:10am UTC](https://forum.freecodecamp.org/t/check-writer-c-help-please/63841/3 "2021-01-16T06:10:32Z")

</div>

Closed on January 16, 2021, 6:10am UTC


