# Thread: how to convert integers into strings.

1. ## how to convert integers into strings.

Hi, I am having a problem to convert integers into strings. For example, (I got this one from the book) it first input \$1920.85, and then it converts into One thousand nine hundred twenty and 85 cents. How can I do that? Can anyone guide me how to do this, and show some simple examples? Thank you.

By the way, here is the question:
Write a program that displays a simulated paycheck
The program should ask the user to enter the date, the payee's name, and the amount of the check (as a floating point number). It should then display a simulated check with the dollar amount spelled out, as shown here:

Date: 12/04/2011

Pay to the order of: Charlie Fontuli \$1920.85

One thousand nine hundred twenty and 85 cents

Be sure to format the numeric value of the check in fixed point notation with two decimal places of precision. Be sure the decimal place always displays, even when the number is zero or has no fractional part. Use either C-strings or string class objects in this program.

Input validation: Do not accept negative dollar amounts, or amounts over \$10,000

2. First off, your title is unclear. In the most direct sense, a numeric value can be converted to a string of number characters.

Code:
```float x = 1234.56;
char y[8] = "1234.56";

printf("%.2f\n%s\n",x,y);

// output:
//
// 1234.56
// 1234.56```
Also, your example shows floating point values, not integers.

A better title might have been "How can I write out numeric values in words?"

---

Second of all, it is considered bad form here (and against the forum Homework Policy) to dump an assignment without showing any attempts to code it on your own.

How can I do that? Can anyone guide me how to do this, and show some simple examples?
The questions you ask are vague and unlikely to get a meaningful response. I recommend reading How To Ask Questions The Smart Way.

---

Think about the assignment, and write down on paper how you might go about solving it. Only then should you begin to write code. When you hit a snag, post the code you have written so far with specific questions about the problems you are facing. You are much more likely to get a helpful response if you heed this advice.

3. >_<

I hate when homework or examples delve poorly into localization and internationalization issues.

Soma

4. Hi sorry about that, I just confused on those things and I don't know how to write it down in sentences. (ay yes, I should show the code earlier. I am just too lazy to do the copy and past codes.)
Here is the code:
Code:
```.
#include<iostream>
#include<cstring>
#include<iomanip>
usingnamespace std;

int main()
{
constint NAME_SIZE = 20; // Size of an array.
constint DATE_SIZE = 20; // Size of the date array.
constint WAGE = 7; // Size of the wage array.
char payDate[DATE_SIZE]; // To hold the size of pay date input.
char payeeName[NAME_SIZE]; // To hold the size of payee's name input.
char input[WAGE]; // To hold the size of dollar amount input.
double payCheck;

cout << "This program can display a simulated paycheck.\n";
cout << "Enter the pay date in (mm/dd/yy): ";
cin.getline(payDate, DATE_SIZE);
cout << "Enter the payee's name: ";
cin.getline(payeeName, NAME_SIZE);
cout << "Enter the dollar amount in the form nnnn.nn: ";
cin.getline(input, WAGE);
payCheck = atof(input); // Convert to double.

// Input Validation.

while (payCheck <= -0 || payCheck > 9999.99)
{
cout << "This program does not accpet negative dollar amounts, "
<< "or amounts over \$10000.\n";
cout << "Please enter a valid number again: ";
cin >> payCheck;
}
// Formating the numeric output.

cout << setprecision(2) << fixed << showpoint;
cout << right << setw(45) << "Date: " << payDate << endl;
cout << endl << endl;
cout << "Pay to the Order of: " << payeeName << setw(16) << "\$" << payCheck << endl;
cout << endl;

system ("PAUSE");

return 0;
}
```
.

5. Originally Posted by inobProgram
Hi sorry about that, I just confused on those things and I don't know how to write it down in sentences. (ay yes, I should show the code earlier. I am just too lazy to do the copy and past codes.)
Of course you do.
One thing you must know is that a computer is dumb, so you have to explain to it in simple instructions how to achieve things. But your brain does not need that.
Anyway, what you should do it just think about how you would do it yourself with pen and paper if you were given such a problem. That mostly explains the logical structure your program needs to follow. After that, it's just a matter of syntax, and that, we can help you with.

6. Okay, thanks for your tips ^_^. I will try that to do some programming.