((num%10)?one[num%10]:1)
I would assume that the "one" array returns a char pointer?
It is complaining because "one[num%10]" and "1" are not the same type...
Just like yesterday, I won't give you the code - not in a form you can use, anyway :laugh:
I have to leave you something to do!
So: Here is what I would do (but remember that you will need to re-work this into C++, this is psuedo code in C# style syntax and won't compile)
1) Set up three arrays of strings:
string[] digitsWords = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
string[] teensWords = { "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
string[] tensWords = { "", "", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
These cover the three case we talked about.
2) Set up a function to use them. It takes an integer and a buffer, and returns a char pointer. It will put the words into the buffer, so make it 100 characters or so it won't run off the end! Call it NumberToWords:
char* NumberToWords(int value, char* buffer)
3) If the function, check the value is between 0 and 99 - if it isn't, put an error message in the buffer!
4) Break the value into the tens part (value / 10) and the digits part (value % 10)
5)
if (value <= 9)
{
copy digitsWords[value] to buffer
}
else if (value <= 19)
{
copy teensWords[digits] to buffer
}
else
{
copy tensWords[tens] to buffer
if (digit != 0)
{
append "-" to buffer
append digitsWords[digits] to buffer
}
}
6) return buffer.
That should be pretty much what you are doing already!
The reason I would put this in a function is twofold: It is easier to read, and it is easier to test - you don't have to type in each number, you can set up a loop which tests all the numbers from -1 to 100 and makes sure you get the right result for each!