is there a way to make it so i can have a switch change the number 127 into one two seven in that order and to recognize which place a number(such as 1s 10s 100s....etc) is in so i can have the program out put the number in words
yeah could you comment it so i can better understand it
this part in particular
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void convertIntToWords(int num) {
int i;
int digit;
for (i=1;i<=10000;i*=10) {
if (floor(num/i==0)) {
i/=10;
break;
}
}
if (i>=10000) i/=10;
for (int j=i;j>=1;j/=10) {
digit=(int)floor(num/j);
num-=digit*j;
switch (digit) {
The index operator on strings is zero based, so the loop arounf the switch statement should initialise i to 0.
You also do not need to try and case the individual elements to int - you can switch on the Char directly
To get the position part (thousdand, hundred, etc.) I would suggest a second int, initialised to Length and decrementing in the loop.
A second switch statement would use this to output the position
So the loop would become
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
for (int i = 0, int j=length;length >= i; i++,j--)
{
switch(Number[i])
{
case'0':
...
}
switch (j)
{
case 3 :
cout << "hundred ";
break;
case 4 :
cout << "thousand ";
break
}
}
Then all you have to do is add a few additional rules to handle commas etc
EG To have the output 'One hunderd and twenty three'