Hello c++ experts. Please help me with this kind of program >.<
i wanted to make my integer converted to string.
For ex. I input "1" and the output must be in string "one".
Sorry if i request this just need this for my homework.

Thanks in advance!

Are we talking about the full range of int, or just the ten decimal digits? The latter is trivial while the former is not.

Well getting a specified range would be nice... but my general thought would be something in the line of:

-Check the length of the integer provided (amount of chars)...
-Write a comparison in to resolve each amount (eg. 3 chars would resolve to "hundred")
-Check the very first digit
-Write a comparison to resolve the first digit (eg. "2" would resolve to "two")
-Add in additional comparisons for each value with a special naming (eg. "eleven", "twenty" etc.)
-Run input through a loop removing one digit at a time and running the result through the same checks again

there might be an easier way, and the larger range you wish to include the more checks you need to enter...

but I believe its easy to understand and code even for a beginner...

One thought for it.
Make an array of strings like strArrayStringNumber[10];
Which will have value {"zero","one", "two", "three", ..upto..."ten"}
Then taking one digit at a time, pass it into array like if number is 213
take 2 first and call strArrayStringNumber[2], it will give corresponding string.
So on for rest of the string.

One thought for it.
Make an array of strings like strArrayStringNumber[10];
Which will have value {"zero","one", "two", "three", ..upto..."ten"}
Then taking one digit at a time, pass it into array like if number is 213
take 2 first and call strArrayStringNumber[2], it will give corresponding string.
So on for rest of the string.

I like this approach, would work well for each digit individually... but how would you implement it to return for example "four-hundred-seventy-five"?

How do YOU think you would do it. Are you looking for someone to outright do your homework for you?

I see absolutely no effort on your part. Did you even try to do it? Did you write any code?

If you post code and perhaps show that you even attempted it, you will probably get much more help than blindly giving your assignment to everyone to do for you.

The complexity depends on the scalability. If you want it to handle 'hundreds', 'thousands', etc, it would need a little more lines of code. But for 'tens', Use an Array as tajendra said. For English Language, There ARE SEVERAL WAYS TO IMPLEMENT THIS. You may use a string array up to 20. Greater than 'Twenty', Use another array to take its prefix, e.g Twenty-, Thirty-. etc. *OR use a single digit comparisons(limited)... Thir + (teen, ty), Four+ (teen, ty), etc.
I wanted to paste a code snippet for you, but, obviously you haven't made any ATTEMPT.
When you do, I can help more....

This article has been dead for over six months. Start a new discussion instead.