1. Number to Word (Billions)

Hi i would just like to ask how or what's the logic needed to make a c program converting a number to a word?

example.
1,000,000 = one million
1000000 = one million
1000000.00 = one million (or one million dollars zero cents)
1,000000 = one million

i'm really finding it hard because of the commas, the decimal point, and that it's limit is 9,999,999,999 = nine billion nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine.

i know i should use modulus=% to separate the digits. but what about the commas and the decimal point?

thanks!

2. Post what you already have.

A hint - get rid of all commas before you begin.

3. Originally Posted by myphilosofi
i know i should use modulus=% to separate the digits.
Some numbers will be beyond the range guaranteed even for unsigned long, so you would need to use long long or some non-standard integer type with sufficient range, or just use a string (in which case you do not need to use % since you check the characters directly).

4. also , do not provide any info - get rid of them before processing your number

5. Here's an idea.
Code:
```/* returns string representation of number in ones column. Ex. 3 -> three */
string ones(int num);

/* returns string representation of number in tens column. Ex. 3 -> thirty */
string tens(int num);```
Now break the numbers down into the hundreds form for each significant place (billions, millions, thousands, hundreds). Use the % operator to get each value and the above functions to get the string representations of those values. Then stick them all together with the terms for each significant place.

Code:
```ex:
31, 821
-> 031
-> 0 -> ""
-> 3 -> thirty
-> 1 -> one
Thousand
-> 821
-> 8 -> eight (using ones column name since it's the same as hundreds)
Hundred
-> 21 -> 2 -> twenty
-> 1 -> one

Result: Thirty one thousand eight hundred twenty one.```

6. Here's what i've done so far..

Code:
```#include<stdio.h>
#include<string.h>

int main(void)
{
char numin[100];
char ones[100];
char tens[100];
char hundreds[100];

int numl;
int x;

scanf("%s", numin);

numl = strlen(numin);

if (numl==1)
{
switch(numin[0])
{
case '0':{ printf("zero dollar\n"); break;}
case '1':{ printf("one dollar\n"); break;}
case '2':{ printf("two dollars\n"); break;}
case '3':{ printf("three dollars\n"); break;}
case '4':{ printf("four dollars\n"); break;}
case '5':{ printf("five dollars\n"); break;}
case '6':{ printf("six dollars\n"); break;}
case '7':{ printf("seven dollars\n"); break;}
case '8':{ printf("eight dollars\n"); break;}
case '9':{ printf("nine dollars\n"); break;}
}
}

else if (numl==2)
{
switch(numin[0])
{

case '0':
{
switch(numin[1])
{
case '0': {printf("zero dollar\n"); break;}
case '1': {printf("one dollar\n"); break;}
case '2': {printf("two dollars \n"); break;}
case '3': {printf("three dollars \n"); break;}
case '4': {printf("four dollars \n"); break;}
case '5': {printf("five dollars \n"); break;}
case '6': {printf("six dollars \n"); break;}
case '7': {printf("seven dollars \n"); break;}
case '8': {printf("eight dollars \n"); break;}
case '9': {printf("nine dollars \n"); break;}
}break;

}

case '1':
{
switch(numin[1])
{
case '0': {printf("ten dollars \n"); break;}
case '1': {printf("eleven dollars \n"); break;}
case '2': {printf("twelve dollars \n"); break;}
case '3': {printf("thirteeen dollars \n"); break;}
case '4': {printf("fourteen dollars \n"); break;}
case '5': {printf("fifteen dollars \n"); break;}
case '6': {printf("sixteen dollars \n"); break;}
case '7': {printf("seventeen dollars \n"); break;}
case '8': {printf("eighteen dollars \n"); break;}
case '9': {printf("nineteen dollars \n"); break;}
}break;

}

case '2':
{
switch(numin[1])
{
case '0': {printf("twenty dollars \n"); break;}
case '1': {printf("twenty one dollars \n"); break;}
case '2': {printf("twenty two dollars \n"); break;}
case '3': {printf("twenty three dollars \n"); break;}
case '4': {printf("twenty four dollars \n"); break;}
case '5': {printf("twenty five dollars \n"); break;}
case '6': {printf("twenty six dollars \n"); break;}
case '7': {printf("twenty seven dollars \n"); break;}
case '8': {printf("twenty eight dollars \n"); break;}
case '9': {printf("twenty nine dollars \n"); break;}
}break;

}

case '3':
{
switch(numin[1])
{
case '0': {printf("thirty dollars \n"); break;}
case '1': {printf("thirty one dollars \n"); break;}
case '2': {printf("thirty two dollars \n"); break;}
case '3': {printf("thirty three dollars \n"); break;}
case '4': {printf("thirty four dollars \n"); break;}
case '5': {printf("thirty five dollars \n"); break;}
case '6': {printf("thirty six dollars \n"); break;}
case '7': {printf("thirty seven dollars \n"); break;}
case '8': {printf("thirty eight dollars \n"); break;}
case '9': {printf("thirty nine dollars \n"); break;}
}
break;

}

case '4':
{
switch(numin[1])
{
case '0': {printf("forty dollars \n"); break;}
case '1': {printf("forty one dollars \n"); break;}
case '2': {printf("forty two dollars \n"); break;}
case '3': {printf("forty three dollars \n"); break;}
case '4': {printf("forty four dollars \n"); break;}
case '5': {printf("forty five dollars \n"); break;}
case '6': {printf("forty six dollars \n"); break;}
case '7': {printf("forty seven dollars \n"); break;}
case '8': {printf("forty eight dollars \n"); break;}
case '9': {printf("forty nine dollars \n"); break;}
}break;
}

case '5':
{
switch(numin[1])
{
case '0': {printf("fifty dollars \n"); break;}
case '1': {printf("fifty one dollars \n"); break;}
case '2': {printf("fifty two dollars \n"); break;}
case '3': {printf("fifty three dollars \n"); break;}
case '4': {printf("fifty four dollars \n"); break;}
case '5': {printf("fifty five dollars \n"); break;}
case '6': {printf("fifty six dollars \n"); break;}
case '7': {printf("fifty seven dollars \n"); break;}
case '8': {printf("fifty eight dollars \n"); break;}
case '9': {printf("fifty nine dollars \n"); break;}
}break;
}

case '6':
{
switch(numin[1])
{
case '0': {printf("sixty dollars \n"); break;}
case '1': {printf("sixty one dollars \n"); break;}
case '2': {printf("sixty two dollars \n"); break;}
case '3': {printf("sixty three dollars \n"); break;}
case '4': {printf("sixty four dollars \n"); break;}
case '5': {printf("sixty five dollars \n"); break;}
case '6': {printf("sixty six dollars \n"); break;}
case '7': {printf("sixty seven dollars \n"); break;}
case '8': {printf("sixty eight dollars \n"); break;}
case '9': {printf("sixty nine dollars \n"); break;}
}break;
}

case '7':
{
switch(numin[1])
{
case '0': {printf("seventy dollars \n"); break;}
case '1': {printf("seventy one dollars \n"); break;}
case '2': {printf("seventy two dollars \n"); break;}
case '3': {printf("seventy three dollars \n"); break;}
case '4': {printf("seventy four dollars \n"); break;}
case '5': {printf("seventy five dollars \n"); break;}
case '6': {printf("seventy six dollars \n"); break;}
case '7': {printf("seventy seven dollars \n"); break;}
case '8': {printf("seventy eight dollars \n"); break;}
case '9': {printf("seventy nine dollars \n"); break;}
}break;
}

case '8':
{
switch(numin[1])
{
case '0': {printf("eighty dollars\n"); break;}
case '1': {printf("eighty one dollars \n"); break;}
case '2': {printf("eighty two dollars \n"); break;}
case '3': {printf("eighty three dollars \n"); break;}
case '4': {printf("eighty four dollars \n"); break;}
case '5': {printf("eighty five dollars \n"); break;}
case '6': {printf("eighty six dollars \n"); break;}
case '7': {printf("eighty seven dollars \n"); break;}
case '8': {printf("eighty eight dollars \n"); break;}
case '9': {printf("eighty nine dollars \n"); break;}
}break;
}

case '9':
{
switch(numin[1])
{
case '0': {printf("ninety dollars \n"); break;}
case '1': {printf("ninety one dollars \n"); break;}
case '2': {printf("ninety two dollars \n"); break;}
case '3': {printf("ninety three dollars \n"); break;}
case '4': {printf("ninety four dollars \n"); break;}
case '5': {printf("ninety five dollars \n"); break;}
case '6': {printf("ninety six dollars \n"); break;}
case '7': {printf("ninety seven dollars \n"); break;}
case '8': {printf("ninety eight dollars \n"); break;}
case '9': {printf("ninety nine dollars \n"); break;}
}break;
}
}

}

else if (numl==3)
{
switch(numin[0])
{
case '0': { printf("zero "); break;}
case '1': { printf("one hundred "); break;}
case '2': { printf("two hundred "); break;}
case '3': { printf("three hundred "); break;}
case '4': { printf("four hundred "); break;}
case '5': { printf("five hundred "); break;}
case '6': { printf("six hundred "); break;}
case '7': { printf("seven hundred "); break;}
case '8': { printf("eight hundred "); break;}
case '9': { printf("nine hundred "); break;}
}

switch(numin[1])
{

case '0':
{
switch(numin[2])
{
case '0': {printf("\n"); break;}
case '1': {printf("and one dollars\n"); break;}
case '2': {printf("and two dollars \n"); break;}
case '3': {printf("and three dollars \n"); break;}
case '4': {printf("and four dollars \n"); break;}
case '5': {printf("and five dollars \n"); break;}
case '6': {printf("and six dollars \n"); break;}
case '7': {printf("and seven dollars \n"); break;}
case '8': {printf("and eight dollars \n"); break;}
case '9': {printf("and nine dollars \n"); break;}
}break;

}

case '1':
{
switch(numin[2])
{
case '0': {printf("and ten dollars \n"); break;}
case '1': {printf("and eleven dollars \n"); break;}
case '2': {printf("and twelve dollars \n"); break;}
case '3': {printf("and thirteeen dollars \n"); break;}
case '4': {printf("and fourteen dollars \n"); break;}
case '5': {printf("and fifteen dollars \n"); break;}
case '6': {printf("and sixteen dollars \n"); break;}
case '7': {printf("and seventeen dollars \n"); break;}
case '8': {printf("and eighteen dollars \n"); break;}
case '9': {printf("and nineteen dollars \n"); break;}
}break;

}

case '2':
{
switch(numin[2])
{
case '0': {printf("and twenty dollars \n"); break;}
case '1': {printf("and twenty one dollars \n"); break;}
case '2': {printf("and twenty two dollars \n"); break;}
case '3': {printf("and twenty three dollars \n"); break;}
case '4': {printf("and twenty four dollars \n"); break;}
case '5': {printf("and twenty five dollars \n"); break;}
case '6': {printf("and twenty six dollars \n"); break;}
case '7': {printf("and twenty seven dollars \n"); break;}
case '8': {printf("and twenty eight dollars \n"); break;}
case '9': {printf("and twenty nine dollars \n"); break;}
}break;

}

case '3':
{
switch(numin[2])
{
case '0': {printf("and thirty dollars \n"); break;}
case '1': {printf("and thirty one dollars \n"); break;}
case '2': {printf("and thirty two dollars \n"); break;}
case '3': {printf("and thirty three dollars \n"); break;}
case '4': {printf("and thirty four dollars \n"); break;}
case '5': {printf("and thirty five dollars \n"); break;}
case '6': {printf("and thirty six dollars \n"); break;}
case '7': {printf("and thirty seven dollars \n"); break;}
case '8': {printf("and thirty eight dollars \n"); break;}
case '9': {printf("and thirty nine dollars \n"); break;}
}
break;

}

case '4':
{
switch(numin[2])
{
case '0': {printf("and forty dollars \n"); break;}
case '1': {printf("and forty one dollars \n"); break;}
case '2': {printf("and forty two dollars \n"); break;}
case '3': {printf("and forty three dollars \n"); break;}
case '4': {printf("and forty four dollars \n"); break;}
case '5': {printf("and forty five dollars \n"); break;}
case '6': {printf("and forty six dollars \n"); break;}
case '7': {printf("and forty seven dollars \n"); break;}
case '8': {printf("and forty eight dollars \n"); break;}
case '9': {printf("and forty nine dollars \n"); break;}
}break;
}

case '5':
{
switch(numin[2])
{
case '0': {printf("and fifty dollars \n"); break;}
case '1': {printf("and fifty one dollars \n"); break;}
case '2': {printf("and fifty two dollars \n"); break;}
case '3': {printf("and fifty three dollars \n"); break;}
case '4': {printf("and fifty four dollars \n"); break;}
case '5': {printf("and fifty five dollars \n"); break;}
case '6': {printf("and fifty six dollars \n"); break;}
case '7': {printf("and fifty seven dollars \n"); break;}
case '8': {printf("and fifty eight dollars \n"); break;}
case '9': {printf("and fifty nine dollars \n"); break;}
}break;
}

case '6':
{
switch(numin[2])
{
case '0': {printf("and sixty dollars \n"); break;}
case '1': {printf("and sixty one dollars \n"); break;}
case '2': {printf("and sixty two dollars \n"); break;}
case '3': {printf("and sixty three dollars \n"); break;}
case '4': {printf("and sixty four dollars \n"); break;}
case '5': {printf("and sixty five dollars \n"); break;}
case '6': {printf("and sixty six dollars \n"); break;}
case '7': {printf("and sixty seven dollars \n"); break;}
case '8': {printf("and sixty eight dollars \n"); break;}
case '9': {printf("and sixty nine dollars \n"); break;}
}break;
}

case '7':
{
switch(numin[2])
{
case '0': {printf("and seventy dollars \n"); break;}
case '1': {printf("and seventy one dollars \n"); break;}
case '2': {printf("and seventy two dollars \n"); break;}
case '3': {printf("and seventy three dollars \n"); break;}
case '4': {printf("and seventy four dollars \n"); break;}
case '5': {printf("and seventy five dollars \n"); break;}
case '6': {printf("and seventy six dollars \n"); break;}
case '7': {printf("and seventy seven dollars \n"); break;}
case '8': {printf("and seventy eight dollars \n"); break;}
case '9': {printf("and seventy nine dollars \n"); break;}
}break;
}

case '8':
{
switch(numin[2])
{
case '0': {printf("and eighty dollars\n"); break;}
case '1': {printf("and eighty one dollars \n"); break;}
case '2': {printf("and eighty two dollars \n"); break;}
case '3': {printf("and eighty three dollars \n"); break;}
case '4': {printf("and eighty four dollars \n"); break;}
case '5': {printf("and eighty five dollars \n"); break;}
case '6': {printf("and eighty six dollars \n"); break;}
case '7': {printf("and eighty seven dollars \n"); break;}
case '8': {printf("and eighty eight dollars \n"); break;}
case '9': {printf("and eighty nine dollars \n"); break;}
}break;
}

case '9':
{
switch(numin[2])
{
case '0': {printf("and ninety dollars \n"); break;}
case '1': {printf("and ninety one dollars \n"); break;}
case '2': {printf("and ninety two dollars \n"); break;}
case '3': {printf("and ninety three dollars \n"); break;}
case '4': {printf("and ninety four dollars \n"); break;}
case '5': {printf("and ninety five dollars \n"); break;}
case '6': {printf("and ninety six dollars \n"); break;}
case '7': {printf("and ninety seven dollars \n"); break;}
case '8': {printf("and ninety eight dollars \n"); break;}
case '9': {printf("and ninety nine dollars \n"); break;}
}break;
}
}
}

else if (numl==4)
{

switch(numin[0])
{
case '0': { printf("zero "); break;}
case '1': { printf("one thousand "); break;}
case '2': { printf("two thousand "); break;}
case '3': { printf("three thousand "); break;}
case '4': { printf("four thousand "); break;}
case '5': { printf("five thousand "); break;}
case '6': { printf("six thousand "); break;}
case '7': { printf("seven thousand "); break;}
case '8': { printf("eight thousand "); break;}
case '9': { printf("nine thousand "); break;}
}

switch(numin[1])
{
case '0': { printf(""); break;}
case '1': { printf("one hundred "); break;}
case '2': { printf("two hundred "); break;}
case '3': { printf("three hundred "); break;}
case '4': { printf("four hundred "); break;}
case '5': { printf("five hundred "); break;}
case '6': { printf("six hundred "); break;}
case '7': { printf("seven hundred "); break;}
case '8': { printf("eight hundred "); break;}
case '9': { printf("nine hundred "); break;}
}

switch(numin[2])
{

case '0':
{
switch(numin[3])
{
case '0': {printf("\n"); break;}
case '1': {printf("and one dollars\n"); break;}
case '2': {printf("and two dollars \n"); break;}
case '3': {printf("and three dollars \n"); break;}
case '4': {printf("and four dollars \n"); break;}
case '5': {printf("and five dollars \n"); break;}
case '6': {printf("and six dollars \n"); break;}
case '7': {printf("and seven dollars \n"); break;}
case '8': {printf("and eight dollars \n"); break;}
case '9': {printf("and nine dollars \n"); break;}
}break;

}

case '1':
{
switch(numin[3])
{
case '0': {printf("and ten dollars \n"); break;}
case '1': {printf("and eleven dollars \n"); break;}
case '2': {printf("and twelve dollars \n"); break;}
case '3': {printf("and thirteeen dollars \n"); break;}
case '4': {printf("and fourteen dollars \n"); break;}
case '5': {printf("and fifteen dollars \n"); break;}
case '6': {printf("and sixteen dollars \n"); break;}
case '7': {printf("and seventeen dollars \n"); break;}
case '8': {printf("and eighteen dollars \n"); break;}
case '9': {printf("and nineteen dollars \n"); break;}
}break;

}

case '2':
{
switch(numin[3])
{
case '0': {printf("and twenty dollars \n"); break;}
case '1': {printf("and twenty one dollars \n"); break;}
case '2': {printf("and twenty two dollars \n"); break;}
case '3': {printf("and twenty three dollars \n"); break;}
case '4': {printf("and twenty four dollars \n"); break;}
case '5': {printf("and twenty five dollars \n"); break;}
case '6': {printf("and twenty six dollars \n"); break;}
case '7': {printf("and twenty seven dollars \n"); break;}
case '8': {printf("and twenty eight dollars \n"); break;}
case '9': {printf("and twenty nine dollars \n"); break;}
}break;

}

case '3':
{
switch(numin[3])
{
case '0': {printf("and thirty dollars \n"); break;}
case '1': {printf("and thirty one dollars \n"); break;}
case '2': {printf("and thirty two dollars \n"); break;}
case '3': {printf("and thirty three dollars \n"); break;}
case '4': {printf("and thirty four dollars \n"); break;}
case '5': {printf("and thirty five dollars \n"); break;}
case '6': {printf("and thirty six dollars \n"); break;}
case '7': {printf("and thirty seven dollars \n"); break;}
case '8': {printf("and thirty eight dollars \n"); break;}
case '9': {printf("and thirty nine dollars \n"); break;}
}
break;

}

case '4':
{
switch(numin[3])
{
case '0': {printf("and forty dollars \n"); break;}
case '1': {printf("and forty one dollars \n"); break;}
case '2': {printf("and forty two dollars \n"); break;}
case '3': {printf("and forty three dollars \n"); break;}
case '4': {printf("and forty four dollars \n"); break;}
case '5': {printf("and forty five dollars \n"); break;}
case '6': {printf("and forty six dollars \n"); break;}
case '7': {printf("and forty seven dollars \n"); break;}
case '8': {printf("and forty eight dollars \n"); break;}
case '9': {printf("and forty nine dollars \n"); break;}
}break;
}

case '5':
{
switch(numin[3])
{
case '0': {printf("and fifty dollars \n"); break;}
case '1': {printf("and fifty one dollars \n"); break;}
case '2': {printf("and fifty two dollars \n"); break;}
case '3': {printf("and fifty three dollars \n"); break;}
case '4': {printf("and fifty four dollars \n"); break;}
case '5': {printf("and fifty five dollars \n"); break;}
case '6': {printf("and fifty six dollars \n"); break;}
case '7': {printf("and fifty seven dollars \n"); break;}
case '8': {printf("and fifty eight dollars \n"); break;}
case '9': {printf("and fifty nine dollars \n"); break;}
}break;
}

case '6':
{
switch(numin[3])
{
case '0': {printf("and sixty dollars \n"); break;}
case '1': {printf("and sixty one dollars \n"); break;}
case '2': {printf("and sixty two dollars \n"); break;}
case '3': {printf("and sixty three dollars \n"); break;}
case '4': {printf("and sixty four dollars \n"); break;}
case '5': {printf("and sixty five dollars \n"); break;}
case '6': {printf("and sixty six dollars \n"); break;}
case '7': {printf("and sixty seven dollars \n"); break;}
case '8': {printf("and sixty eight dollars \n"); break;}
case '9': {printf("and sixty nine dollars \n"); break;}
}break;
}

case '7':
{
switch(numin[3])
{
case '0': {printf("and seventy dollars \n"); break;}
case '1': {printf("and seventy one dollars \n"); break;}
case '2': {printf("and seventy two dollars \n"); break;}
case '3': {printf("and seventy three dollars \n"); break;}
case '4': {printf("and seventy four dollars \n"); break;}
case '5': {printf("and seventy five dollars \n"); break;}
case '6': {printf("and seventy six dollars \n"); break;}
case '7': {printf("and seventy seven dollars \n"); break;}
case '8': {printf("and seventy eight dollars \n"); break;}
case '9': {printf("and seventy nine dollars \n"); break;}
}break;
}

case '8':
{
switch(numin[3])
{
case '0': {printf("and eighty dollars\n"); break;}
case '1': {printf("and eighty one dollars \n"); break;}
case '2': {printf("and eighty two dollars \n"); break;}
case '3': {printf("and eighty three dollars \n"); break;}
case '4': {printf("and eighty four dollars \n"); break;}
case '5': {printf("and eighty five dollars \n"); break;}
case '6': {printf("and eighty six dollars \n"); break;}
case '7': {printf("and eighty seven dollars \n"); break;}
case '8': {printf("and eighty eight dollars \n"); break;}
case '9': {printf("and eighty nine dollars \n"); break;}
}break;
}

case '9':
{
switch(numin[3])
{
case '0': {printf("and ninety dollars \n"); break;}
case '1': {printf("and ninety one dollars \n"); break;}
case '2': {printf("and ninety two dollars \n"); break;}
case '3': {printf("and ninety three dollars \n"); break;}
case '4': {printf("and ninety four dollars \n"); break;}
case '5': {printf("and ninety five dollars \n"); break;}
case '6': {printf("and ninety six dollars \n"); break;}
case '7': {printf("and ninety seven dollars \n"); break;}
case '8': {printf("and ninety eight dollars \n"); break;}
case '9': {printf("and ninety nine dollars \n"); break;}
}break;
}
}
}

else if (numl==5)
{

switch(numin[0])
{

/*case '0':
{
switch(numin[1])
{
case '0': {printf(""); break;}
case '1': {printf("one dollar\n"); break;}
case '2': {printf("two dollars \n"); break;}
case '3': {printf("three dollars \n"); break;}
case '4': {printf("four dollars \n"); break;}
case '5': {printf("five dollars \n"); break;}
case '6': {printf("six dollars \n"); break;}
case '7': {printf("seven dollars \n"); break;}
case '8': {printf("eight dollars \n"); break;}
case '9': {printf("nine dollars \n"); break;}
}break;

}*/

case '1':
{
switch(numin[1])
{
case '0': {printf("ten thousand "); break;}
case '1': {printf("eleven thousand "); break;}
case '2': {printf("twelve thousand "); break;}
case '3': {printf("thirteeen thousand "); break;}
case '4': {printf("fourteen thousand "); break;}
case '5': {printf("fifteen thousand "); break;}
case '6': {printf("sixteen thousand "); break;}
case '7': {printf("seventeen thousand "); break;}
case '8': {printf("eighteen thousand "); break;}
case '9': {printf("nineteen thousand "); break;}
}break;

}

case '2':
{
switch(numin[1])
{
case '0': {printf("twenty thousand "); break;}
case '1': {printf("twenty one thousand "); break;}
case '2': {printf("twenty two thousand "); break;}
case '3': {printf("twenty three thousand "); break;}
case '4': {printf("twenty four thousand "); break;}
case '5': {printf("twenty five thousand "); break;}
case '6': {printf("twenty six thousand "); break;}
case '7': {printf("twenty seven thousand "); break;}
case '8': {printf("twenty eight thousand "); break;}
case '9': {printf("twenty nine thousand "); break;}
}break;

}

case '3':
{
switch(numin[1])
{
case '0': {printf("thirty thousand "); break;}
case '1': {printf("thirty one thousand "); break;}
case '2': {printf("thirty two thousand "); break;}
case '3': {printf("thirty three thousand "); break;}
case '4': {printf("thirty four thousand "); break;}
case '5': {printf("thirty five thousand "); break;}
case '6': {printf("thirty six thousand "); break;}
case '7': {printf("thirty seven thousand "); break;}
case '8': {printf("thirty eight thousand "); break;}
case '9': {printf("thirty nine thousand "); break;}
}
break;

}

case '4':
{
switch(numin[1])
{
case '0': {printf("forty thousand "); break;}
case '1': {printf("forty one thousand "); break;}
case '2': {printf("forty two thousand "); break;}
case '3': {printf("forty three thousand "); break;}
case '4': {printf("forty four thousand "); break;}
case '5': {printf("forty five thousand "); break;}
case '6': {printf("forty six thousand "); break;}
case '7': {printf("forty seven thousand "); break;}
case '8': {printf("forty eight thousand "); break;}
case '9': {printf("forty nine thousand "); break;}
}break;
}

case '5':
{
switch(numin[1])
{
case '0': {printf("fifty thousand "); break;}
case '1': {printf("fifty one thousand "); break;}
case '2': {printf("fifty two thousand "); break;}
case '3': {printf("fifty three thousand "); break;}
case '4': {printf("fifty four thousand "); break;}
case '5': {printf("fifty five thousand "); break;}
case '6': {printf("fifty six thousand "); break;}
case '7': {printf("fifty seven thousand "); break;}
case '8': {printf("fifty eight thousand "); break;}
case '9': {printf("fifty nine thousand "); break;}
}break;
}

case '6':
{
switch(numin[1])
{
case '0': {printf("sixty thousand "); break;}
case '1': {printf("sixty one thousand "); break;}
case '2': {printf("sixty two thousand "); break;}
case '3': {printf("sixty three thousand "); break;}
case '4': {printf("sixty four thousand "); break;}
case '5': {printf("sixty five thousand "); break;}
case '6': {printf("sixty six thousand "); break;}
case '7': {printf("sixty seven thousand "); break;}
case '8': {printf("sixty eight thousand "); break;}
case '9': {printf("sixty nine thousand "); break;}
}break;
}

case '7':
{
switch(numin[1])
{
case '0': {printf("seventy thousand "); break;}
case '1': {printf("seventy one thousand "); break;}
case '2': {printf("seventy two thousand "); break;}
case '3': {printf("seventy three thousand "); break;}
case '4': {printf("seventy four thousand "); break;}
case '5': {printf("seventy five thousand "); break;}
case '6': {printf("seventy six thousand "); break;}
case '7': {printf("seventy seven thousand "); break;}
case '8': {printf("seventy eight thousand "); break;}
case '9': {printf("seventy nine thousand "); break;}
}break;
}

case '8':
{
switch(numin[1])
{
case '0': {printf("eighty thousand "); break;}
case '1': {printf("eighty one thousand "); break;}
case '2': {printf("eighty two thousand "); break;}
case '3': {printf("eighty three thousand "); break;}
case '4': {printf("eighty four thousand "); break;}
case '5': {printf("eighty five thousand "); break;}
case '6': {printf("eighty six thousand "); break;}
case '7': {printf("eighty seven thousand "); break;}
case '8': {printf("eighty eight thousand "); break;}
case '9': {printf("eighty nine thousand "); break;}
}break;
}

case '9':
{
switch(numin[1])
{
case '0': {printf("ninety thousand "); break;}
case '1': {printf("ninety one thousand "); break;}
case '2': {printf("ninety two thousand "); break;}
case '3': {printf("ninety three thousand "); break;}
case '4': {printf("ninety four thousand "); break;}
case '5': {printf("ninety five thousand "); break;}
case '6': {printf("ninety six thousand "); break;}
case '7': {printf("ninety seven thousand "); break;}
case '8': {printf("ninety eight thousand "); break;}
case '9': {printf("ninety nine thousand "); break;}
}break;
}
}

switch(numin[2])
{
case '0': { printf(""); break;}
case '1': { printf("one hundred "); break;}
case '2': { printf("two hundred "); break;}
case '3': { printf("three hundred "); break;}
case '4': { printf("four hundred "); break;}
case '5': { printf("five hundred "); break;}
case '6': { printf("six hundred "); break;}
case '7': { printf("seven hundred "); break;}
case '8': { printf("eight hundred "); break;}
case '9': { printf("nine hundred "); break;}
}

switch(numin[3])
{

case '0':
{
switch(numin[4])
{
case '0': {printf("\n"); break;}
case '1': {printf("and one dollars\n"); break;}
case '2': {printf("and two dollars \n"); break;}
case '3': {printf("and three dollars \n"); break;}
case '4': {printf("and four dollars \n"); break;}
case '5': {printf("and five dollars \n"); break;}
case '6': {printf("and six dollars \n"); break;}
case '7': {printf("and seven dollars \n"); break;}
case '8': {printf("and eight dollars \n"); break;}
case '9': {printf("and nine dollars \n"); break;}
}break;

}

case '1':
{
switch(numin[4])
{
case '0': {printf("and ten dollars \n"); break;}
case '1': {printf("and eleven dollars \n"); break;}
case '2': {printf("and twelve dollars \n"); break;}
case '3': {printf("and thirteeen dollars \n"); break;}
case '4': {printf("and fourteen dollars \n"); break;}
case '5': {printf("and fifteen dollars \n"); break;}
case '6': {printf("and sixteen dollars \n"); break;}
case '7': {printf("and seventeen dollars \n"); break;}
case '8': {printf("and eighteen dollars \n"); break;}
case '9': {printf("and nineteen dollars \n"); break;}
}break;

}

case '2':
{
switch(numin[4])
{
case '0': {printf("and twenty dollars \n"); break;}
case '1': {printf("and twenty one dollars \n"); break;}
case '2': {printf("and twenty two dollars \n"); break;}
case '3': {printf("and twenty three dollars \n"); break;}
case '4': {printf("and twenty four dollars \n"); break;}
case '5': {printf("and twenty five dollars \n"); break;}
case '6': {printf("and twenty six dollars \n"); break;}
case '7': {printf("and twenty seven dollars \n"); break;}
case '8': {printf("and twenty eight dollars \n"); break;}
case '9': {printf("and twenty nine dollars \n"); break;}
}break;

}

case '3':
{
switch(numin[4])
{
case '0': {printf("and thirty dollars \n"); break;}
case '1': {printf("and thirty one dollars \n"); break;}
case '2': {printf("and thirty two dollars \n"); break;}
case '3': {printf("and thirty three dollars \n"); break;}
case '4': {printf("and thirty four dollars \n"); break;}
case '5': {printf("and thirty five dollars \n"); break;}
case '6': {printf("and thirty six dollars \n"); break;}
case '7': {printf("and thirty seven dollars \n"); break;}
case '8': {printf("and thirty eight dollars \n"); break;}
case '9': {printf("and thirty nine dollars \n"); break;}
}
break;

}

case '4':
{
switch(numin[4])
{
case '0': {printf("and forty dollars \n"); break;}
case '1': {printf("and forty one dollars \n"); break;}
case '2': {printf("and forty two dollars \n"); break;}
case '3': {printf("and forty three dollars \n"); break;}
case '4': {printf("and forty four dollars \n"); break;}
case '5': {printf("and forty five dollars \n"); break;}
case '6': {printf("and forty six dollars \n"); break;}
case '7': {printf("and forty seven dollars \n"); break;}
case '8': {printf("and forty eight dollars \n"); break;}
case '9': {printf("and forty nine dollars \n"); break;}
}break;
}

case '5':
{
switch(numin[4])
{
case '0': {printf("and fifty dollars \n"); break;}
case '1': {printf("and fifty one dollars \n"); break;}
case '2': {printf("and fifty two dollars \n"); break;}
case '3': {printf("and fifty three dollars \n"); break;}
case '4': {printf("and fifty four dollars \n"); break;}
case '5': {printf("and fifty five dollars \n"); break;}
case '6': {printf("and fifty six dollars \n"); break;}
case '7': {printf("and fifty seven dollars \n"); break;}
case '8': {printf("and fifty eight dollars \n"); break;}
case '9': {printf("and fifty nine dollars \n"); break;}
}break;
}

case '6':
{
switch(numin[4])
{
case '0': {printf("and sixty dollars \n"); break;}
case '1': {printf("and sixty one dollars \n"); break;}
case '2': {printf("and sixty two dollars \n"); break;}
case '3': {printf("and sixty three dollars \n"); break;}
case '4': {printf("and sixty four dollars \n"); break;}
case '5': {printf("and sixty five dollars \n"); break;}
case '6': {printf("and sixty six dollars \n"); break;}
case '7': {printf("and sixty seven dollars \n"); break;}
case '8': {printf("and sixty eight dollars \n"); break;}
case '9': {printf("and sixty nine dollars \n"); break;}
}break;
}

case '7':
{
switch(numin[4])
{
case '0': {printf("and seventy dollars \n"); break;}
case '1': {printf("and seventy one dollars \n"); break;}
case '2': {printf("and seventy two dollars \n"); break;}
case '3': {printf("and seventy three dollars \n"); break;}
case '4': {printf("and seventy four dollars \n"); break;}
case '5': {printf("and seventy five dollars \n"); break;}
case '6': {printf("and seventy six dollars \n"); break;}
case '7': {printf("and seventy seven dollars \n"); break;}
case '8': {printf("and seventy eight dollars \n"); break;}
case '9': {printf("and seventy nine dollars \n"); break;}
}break;
}

case '8':
{
switch(numin[4])
{
case '0': {printf("and eighty dollars\n"); break;}
case '1': {printf("and eighty one dollars \n"); break;}
case '2': {printf("and eighty two dollars \n"); break;}
case '3': {printf("and eighty three dollars \n"); break;}
case '4': {printf("and eighty four dollars \n"); break;}
case '5': {printf("and eighty five dollars \n"); break;}
case '6': {printf("and eighty six dollars \n"); break;}
case '7': {printf("and eighty seven dollars \n"); break;}
case '8': {printf("and eighty eight dollars \n"); break;}
case '9': {printf("and eighty nine dollars \n"); break;}
}break;
}

case '9':
{
switch(numin[4])
{
case '0': {printf("and ninety dollars \n"); break;}
case '1': {printf("and ninety one dollars \n"); break;}
case '2': {printf("and ninety two dollars \n"); break;}
case '3': {printf("and ninety three dollars \n"); break;}
case '4': {printf("and ninety four dollars \n"); break;}
case '5': {printf("and ninety five dollars \n"); break;}
case '6': {printf("and ninety six dollars \n"); break;}
case '7': {printf("and ninety seven dollars \n"); break;}
case '8': {printf("and ninety eight dollars \n"); break;}
case '9': {printf("and ninety nine dollars \n"); break;}
}break;
}
}
}
return 0;

}```

7. problem is, i don't know what to do if the user enters commas and a decimal point..
and my classmates say that scanf is not allowed. what should i do?

8. Originally Posted by myphilosofi
Here's what i've done so far..
That code is terribly unwieldy. As Perspective suggested, you should break the code down into functions that can be reused.

Originally Posted by myphilosofi
i don't know what to do if the user enters commas and a decimal point..
Remove the commas as cyberfish suggested. If there is a decimal point, you need to take into account the cents.

Originally Posted by myphilosofi
and my classmates say that scanf is not allowed. what should i do?
Use fgets() instead. You could safely use scanf() if you provided a field width for the string format specifier, but as it stands your code is vulnerable to buffer overflow.

9. here's another one:

Code:
```void cents(char tenscent, char onescent, char salita[]){

switch(tenscent){
case '0': specialcase2(onescent, salita);return; break;
case '1': specialcase(onescent, salita); return; break;
case '2': strcpy(salita, " and twenty "); break;
case '3': strcpy(salita, " and thirty "); break;
case '4': strcpy(salita, " and forty "); break;
case '5': strcpy(salita, " and fifty "); break;
case '6': strcpy(salita, " and sixty "); break;
case '7': strcpy(salita, " and seventy "); break;
case '8': strcpy(salita, " and eighty "); break;
case '9': strcpy(salita, " and ninety "); break;
}

int main(){

char num[200] = "";
char centwords[200] = "";
char in;
char outputwords[200] = "";
char extrastring[200] = "";
char extrastring2[200] = "";
int counter = 0;
int counternew = 0;

while (in != '\n'){
in = getchar();
if ((in >= '0') && (in <= '9')){
num[counter] = in;
counter = counter + 1;
}
}

cents(num[counter - 2], num[counter -1], centwords);

while(counternew <= (counter - 1)){
whole(num[counternew], extrastring, counter, num[counternew + 1]);
strcat(extrastring2, extrastring);
counternew = counternew + 1;
counter = counter - 1;
}

strcat(extrastring2, centwords);
printf("%s\n", extrastring2);

return 0;

}```

10. 1. no need to break after return
2. while (in != '\n') - your in var is not initialized

11. this is not mine but the one who made this said this is right..but i can't understand it:

Code:
```#include<stdio.h>

void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","seventy"," eighty"," ninety"};

void main()
{
long n;
clrscr();
printf(" Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/1000000),"million");
pw(((n/100000)%10),"hundred thousand");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}

void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}```

12. This last program is on the right track. I would add a getchar() to pull the newline char off just after the scanf() call, but other than that, it looks good. Did you run it yet? (I have not).

I didn't see your very long program until now, but that is definitely on the wrong track. It may produce fine results, but it's way too large.

When you get that urge to do something like that next time, I want you to pull back instinctively and say "no, that can't be right", to yourself. The problem with it is that you didn't find a way to organize the words - to represent the data - so you went ahead and just wrote out every possibility, almost.

We can applaud your effort, however!

13. by the way, you should only have "and" after a decimal place. 3,485 should be "Three thousand four hundred eighty five" not "three thousand four hundred and eighty five".

14. "zero dollar" should be plural - "zero dollars"

Never just copy and paste large sections of code over and over! If you had to make 9 billion plastic pegs would you make 9 billion individual moulds for them too? No, you make just a few and use those over and over.
Resue man, REUSE!

That other person's program should have the arrays as const char*[] and it looks to be on the right track except that it wont work much past 2 billion, or 4 billion if you switch it to unsigned. The string literals in the array shouldn't have any spaces. It also isn't perfect because it doesn't contain the word "and" anywhere.

15. :)

Hi! Thanks for all the replies!

This is the code of my classmate that he shared with me.
I just edited it so that it'll still work without the cents places.
But i don't know what to do with the whole number part.

The last program i've posted, i really can't understand and
it works with whole numbers but does not work with numbers with commas
and with decimal places.

Hope you still comment and give advice...thanks!

Code:
```#include<stdio.h>
#include<string.h>

void cents(char tenscent, char onescent, char salita[])
{
switch(tenscent)
{
case '0':
{
//specialcase2(onescent, salita);return; break;
switch (onescent)
{
case '0': strcat(salita, " "); break;
case '1': strcat(salita, " and one cent"); break;
case '2': strcat(salita, " and two cents"); break;
case '3': strcat(salita, " and three cents"); break;
case '4': strcat(salita, " and four cents"); break;
case '5': strcat(salita, " and five cents"); break;
case '6': strcat(salita, " and six cents"); break;
case '7': strcat(salita, " and seven cents"); break;
case '8': strcat(salita, " and eight cents"); break;
case '9': strcat(salita, " and nine cents"); break;
}
}

case '1':
{
switch (onescent)
{
case '0': strcat(salita, " and ten cents"); break;
case '1': strcat(salita, " and eleven cents"); break;
case '2': strcat(salita, " and twelve cents"); break;
case '3': strcat(salita, " and thirteen cents"); break;
case '4': strcat(salita, " and fourteen cents"); break;
case '5': strcat(salita, " and fifteen cents"); break;
case '6': strcat(salita, " and sixteen cents"); break;
case '7': strcat(salita, " and seventeen cents"); break;
case '8': strcat(salita, " and eighteen cents"); break;
case '9': strcat(salita, " and nineteen cents"); break;
}
}
case '2': strcat(salita, " and twenty"); break;
case '3': strcat(salita, " and thirty"); break;
case '4': strcat(salita, " and forty"); break;
case '5': strcat(salita, " and fifty"); break;
case '6': strcat(salita, " and sixty"); break;
case '7': strcat(salita, " and seventy"); break;
case '8': strcat(salita, " and eighty"); break;
case '9': strcat(salita, " and ninety"); break;
}

switch (onescent)
{
case '0': strcat(salita, " "); break;
case '1': strcat(salita, " one cents"); break;
case '2': strcat(salita, " two cents"); break;
case '3': strcat(salita, " three cents"); break;
case '4': strcat(salita, " four cents"); break;
case '5': strcat(salita, " five cents"); break;
case '6': strcat(salita, " six cents"); break;
case '7': strcat(salita, " seven cents"); break;
case '8': strcat(salita, " eight cents"); break;
case '9': strcat(salita, " nine cents"); break;
}
}

int main()
{
char num[200] = "";
char centwords[200] = "";
char in;
//char outputwords[200] = "";
//char extrastring[200] = "";
char extrastring2[200] = "";
char dec[200] = "";
int counter = 0;
int counterdec = 0;
//int counternew = 0;

while (in != '\n')
{
in = getchar();

if (((in >= '0') && (in <= '9')) || (in == '.'))
{
num[counter] = in;
counter = counter + 1;
}
}

if (num[counter-3] == '.')
{
cents(num[counter - 2], num[counter -1], centwords);
}

/* while(counternew <= (counter - 1))
{
whole(num[counternew], extrastring, counter, num[counternew + 1]);
strcat(extrastring2, extrastring);
counternew = counternew + 1;
counter = counter - 1;
}
*/
strcat(extrastring2, centwords);
printf("%s\n", extrastring2);

return 0;
}```