Convert int numbers to words

Write a c++program that asks the user to enter positive integer numbers without points between 0 and 999. Then check the amount and print in words.
You need to use dynamic ragged arrays..

This is my solution but I'm not sure if this is the right way for dynamic ragged array???:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
int main() 
{ 
char *Units[]={"ZERO", "ONE", "TWO", "THREE","FOUR","FIVE", "SIX","SEVEN", "EIGHT", "NINE"}; 
char *teens []={"TEN", "ELEVEN", "TWELVE","THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN","NINETEEN" }; 
char *hundreds []= {"HUNDRED"}; 
char *tens []={ "ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"}; 


[code]int num; 
cout<<"Enter the check amount "; 
cin>>num; 
cout<<"The check amount in words "<<endl; 

while(num > 0) 
{ 
int d=0; 
if(num >= 100) 
{ 

d = num / 100; 
cout<<Units[d]<<' '; 
cout<<*hundreds<<' ';; 
num = num % 100; 
} 
else if(num >= 20) 
{ 
d = num / 10; 
cout<<tens[d]<<' '; 
num = num % 10; 
} 
else if(num >= 10 && num < 20) 
{ 
d = num % 10; 
cout<<teens[d]<<' '; 
num = num / 100; 
} 
else 
{ 
cout<<Units[num]<<' '; 
num = num / 10; 
} 
}
Last edited on
Your arrays are neither dynamic nor ragged.
I see no check that the input is between 0 and 999.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.