Hi i'm new to using c++ and i would like to ask if you could help me out. I have to somehow get a working c++ program that will allow me to convert any one, two or three digit positive integer into words using string/array method. Say, 111 will be converted into one hundred and eleven. I would greatly appreciate it if you could help me out.
7h3.doctorat3
0
Newbie Poster
Recommended Answers
Jump to PostI would put the numerical representation of the number into an std::string. From here you can access each digit separately:
std::string number = "123"; std::cout << number[0]; //outputs '1'
You would then have to have a giant switch statement to convert a '1' to "one", etc.
…
Jump to PostGoogle it. I bet the generic algorithm for this has been done many times before.
If you're only using three digits max it shouldn't be too hard.
For example the following looks like a useful template, written in java though.
All 5 Replies
daviddoria
334
Posting Virtuoso
Featured Poster
iamthwee
mrnutty
761
Senior Poster
daviddoria
334
Posting Virtuoso
Featured Poster
mrnutty
761
Senior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.