Hello, i need help to convert any 1, 2, or 3 digit number into words using string/array method in C++. For example, 111 should read one hundred and eleven, 011 should read eleven, 001 should read one. I would much appreciate it if you could help me solve this problem. I have done a little of it so far and it is correct up to this point and no modifications should be necessary. It should also be short (30 lines max.)
using namespace std;
cout<<"Please enter a three digit number";
> I have done a little of it so far and it is correct up to this point
This is true. It is very hard to get array declarations and a prompt for input wrong. :D Ed is inclined to believe that you accidentally pasted only a portion of your code rather than all of it.
Looks like you're on the right track, just keep in mind that if you have to account for all 999 cases of 3 digit numbers then it would be advantageous for you to look for word aliasing. For instance, eleven occurs 11 times within that range. hundred occurs 900 times etc. Looks like you're headed that way.
No one is here to give you a copy paste code, you have to do work for that.
You work quite fine until now..........
Further what you have do thats I will explain bellow
Take user input in a integer type variable for example num
Use a string variable to store converted input in word and initialize it with NULL
Then you have to check your last two digit number is less then 20 or not
IF LASTTWODIGIT <20 THEN
INWORD=b[DIGIT_AT_TENTH_PLACE]+" "+a[DIGIT_AT_ONES_PLACE]+" "+INWORD