Number Writer

closed account (1v5E3TCk)
Hello everyone, i want to make a program which writes the number whose you input the reading. i made one which writes the reading of number but i cant do this one. can anyone help?
closed account (Dy7SLyTq)
could you be more clear
closed account (1v5E3TCk)
sorry for my english
i mean when you input one hundred and twenty-one it outputs 152.
how can i make a program like that?
closed account (1v5E3TCk)
i code that but i want the opposite


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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <iostream>
#include <string>
using namespace std;

void   birler(long long x){
   if(x==0){cout<<"zero";}
   if(x==1){cout<<"one";}
   if(x==2){cout<<"two";}
   if(x==3){cout<<"three";}
   if(x==4){cout<<"four";}
   if(x==5){cout<<"five";} 
   if(x==6){cout<<"six";}
   if(x==7){cout<<"seven";}
   if(x==8){cout<<"eight";}
   if(x==9){cout<<"nine";}   
   }
void   onlar(long long x) {
   if(x<10) {birler(x);}
   if(x==10){cout<<"ten";}
   if(x==11){cout<<"eleven";}
   if(x==12){cout<<"twelve";}
   if(x==13){cout<<"thirteen";}
   if(x==14){cout<<"fourteen";} 
   if(x==15){cout<<"fifteen";}
   if(x==16){cout<<"sixteen";}
   if(x==17){cout<<"seventeen";}
   if(x==18){cout<<"eighteen";}   
   if(x==19){cout<<"nineteen";}
   if(x==20){cout<<"twenty";}
   if(x>20&&x<30) {cout<<"twenty-"; x=x-20; birler(x);}
   if(x==30){cout<<"thirty";}
   if(x>30&&x<40) {cout<<"thirty-"; x=x-30; birler(x);}       
   if(x==40){cout<<"fourty";}
   if(x>40&&x<50) {cout<<"fourty-"; x=x-40; birler(x);}         
   if(x==50){cout<<"fifty";}
   if(x>50&&x<60) {cout<<"fifty-"; x=x-50; birler(x);}         
   if(x==60){cout<<"sixty";}
   if(x>60&&x<70) {cout<<"sixty-"; x=x-60; birler(x);}         
   if(x==70){cout<<"seventy";}
   if(x>70&&x<80) {cout<<"seventy-"; x=x-70; birler(x);}
   if(x==80){cout<<"eighty";}
   if(x>80&&x<90) {cout<<"eighty-"; x=x-90; birler(x);}         
   if(x==90){cout<<"ninety";}
   if(x>90&&x<100) {cout<<"ninety-"; x=x-90; birler(x);}            
            }
            
void   yuzler(long long x){
   if(x<100) {onlar(x);}
   if(x==100)         {cout<<"one hundret ";}
   if(x>100&&x<200)   {cout<<"one hundret "; x=x-100; onlar(x);}
   if(x==200)         {cout<<"two hundret ";}
   if(x>200&&x<300)   {cout<<"two hundret "; x=x-200; onlar(x);}          
   if(x==300)         {cout<<"three hundret ";}
   if(x>300&&x<400)   {cout<<"three hundret "; x=x-300; onlar(x);}          
   if(x==400)         {cout<<"four hundret ";}
   if(x>400&&x<500)   {cout<<"four hundret "; x=x-400; onlar(x);}          
   if(x==500)         {cout<<"five hundret ";}
   if(x>500&&x<600)   {cout<<"five hundret "; x=x-500; onlar(x);}          
   if(x==600)         {cout<<"six hundret ";}
   if(x>600&&x<700)   {cout<<"six hundret "; x=x-600; onlar(x);}          
   if(x==700)         {cout<<"seven hundret ";}
   if(x>700&&x<800)   {cout<<"seven hundret "; x=x-700; onlar(x);}          
   if(x==800)         {cout<<"eight hundret ";}
   if(x>800&&x<900)   {cout<<"eight hundret "; x=x-800; onlar(x);}
   if(x==900)         {cout<<"nine hundret ";}
   if(x>900&&x<1000)  {cout<<"nine hundret "; x=x-900; onlar(x);}
   }
   
void   binler(long long x){
   if(x<1000){yuzler(x);}
   if(x==1000)         {cout<<"one thousand ";}
   if(x>1000&&x<2000)  {cout<<"one thousand "; x=x-1000; yuzler(x);}
   if(x==2000)         {cout<<"two thousand ";}
   if(x>2000&&x<3000)  {cout<<"two thousand "; x=x-2000; yuzler(x);}          
   if(x==3000)         {cout<<"three thousand ";}
   if(x>3000&&x<4000)  {cout<<"three thousand "; x=x-3000; yuzler(x);}          
   if(x==4000)         {cout<<"four thousand ";}
   if(x>4000&&x<5000)  {cout<<"four thousand "; x=x-4000; yuzler(x);}          
   if(x==5000)         {cout<<"five thousand ";}
   if(x>5000&&x<6000)  {cout<<"five thousand "; x=x-5000; yuzler(x);}          
   if(x==6000)         {cout<<"six thousand ";}
   if(x>6000&&x<7000)  {cout<<"six thousand "; x=x-6000; yuzler(x);}          
   if(x==7000)         {cout<<"seven thousand ";}
   if(x>7000&&x<8000)  {cout<<"seven thousand "; x=x-7000; yuzler(x);}          
   if(x==8000)         {cout<<"eight thousand ";}
   if(x>8000&&x<9000)  {cout<<"eight thousand "; x=x-8000; yuzler(x);}
   if(x==9000)         {cout<<"nine thousand ";}
   if(x>9000&&x<10000) {cout<<"nine thousand "; x=x-9000; yuzler(x);}
     
   }
   
void   onbinler(long long x){
   if(x<10000) {binler(x);}
   if(x==10000)         {cout<<"ten thousand ";}
    if(x>10000&&x<11000) {cout<<"ten thousand "; x=x-10000; yuzler(x);} 
   if(x==11000)         {cout<<"eleven thousand ";}
    if(x>11000&&x<12000) {cout<<"eleven thousand "; x=x-11000; yuzler(x);}
   if(x==12000)         {cout<<"twelve thousand ";}
    if(x>12000&&x<13000) {cout<<"twelve thousand "; x=x-12000; yuzler(x);}
   if(x==13000)         {cout<<"thirteen thousand ";}
    if(x>13000&&x<14000) {cout<<"thirteen thousand "; x=x-13000; yuzler(x);}
   if(x==14000)         {cout<<"fourteen thousand ";}
    if(x>14000&&x<15000) {cout<<"fourteen thousand "; x=x-14000; yuzler(x);}
   if(x==15000)         {cout<<"fifteen thousand ";}
    if(x>15000&&x<16000) {cout<<"fifteen thousand "; x=x-15000; yuzler(x);}
   if(x==16000)         {cout<<"sixteen thousand ";}
    if(x>16000&&x<17000) {cout<<"sixteen thousand "; x=x-16000; yuzler(x);}
   if(x==17000)         {cout<<"seventeen thousand ";}
    if(x>17000&&x<18000) {cout<<"seventeen thousand "; x=x-17000; yuzler(x);}
   if(x==18000)         {cout<<"eighteen thousand ";}
    if(x>18000&&x<19000) {cout<<"eighteen thousand "; x=x-18000; yuzler(x);}
   if(x==19000)         {cout<<"nineteen thousand ";}
    if(x>19000&&x<20000) {cout<<"nineteen thousand "; x=x-19000; yuzler(x);}
   if(x==20000)         {cout<<"twenty thousand ";} 
    if(x>20000&&x<30000) {cout<<"twenty-"; x=x-20000; binler(x);}        
   if(x==30000)         {cout<<"thirty thousand ";}
    if(x>30000&&x<40000) {cout<<"thirty-"; x=x-30000; binler(x);}        
   if(x==40000)         {cout<<"fourty thousand ";}
    if(x>40000&&x<50000) {cout<<"fourty-"; x=x-40000; binler(x);}        
   if(x==50000)         {cout<<"fifty thousand ";}
    if(x>50000&&x<60000) {cout<<"fifty-"; x=x-50000; binler(x);}        
   if(x==60000)         {cout<<"sixty thousand ";}
    if(x>60000&&x<70000) {cout<<"sixty-"; x=x-60000; binler(x);}        
   if(x==70000)         {cout<<"seventy thousand ";}
    if(x>70000&&x<80000) {cout<<"seventy-"; x=x-70000; binler(x);}                
   if(x==80000)         {cout<<"eighty thousand ";}
    if(x>80000&&x<90000) {cout<<"eighty-"; x=x-80000; binler(x);}        
   if(x==90000)         {cout<<"ninety thousand ";}
    if(x>90000&&x<100000){cout<<"ninety-"; x=x-90000; binler(x);}         
            }         
int main(){
    long long x;
    int y;
    while(1)
    {
    cout<<"Ingilizcesini ogrenmek istediginiz sayiyi giriniz.\n";
    cin>>x;
    if(x<10){birler(x);} 
    if(x>9&&x<100){onlar(x);}
    if(x>99&&x<1000){yuzler(x);}
    if(x>999&&x<10000){binler(x);}
    if(x>9999&&x<100000){onbinler(x);}
    if(x>99999&&x<1000000){yuzbinler(x);}
    if(x>999999&&x<10000000){milyonlar(x);}
    if(x>9999999&&x<100000000){onmilyonlar(x);}
    if(x>99999999&&x<1000000000){yuzmilyonlar(x);}
    if(x>999999999){cout<<"Cok buyuk bir sayi girdiniz.\nTekrar deneyin."; continue;}
    
    do{
    cout<<"\nLutfen seciminizi yapin.\n";
    cout<<"1.Yeni sayi gir.\n2.Cikis";
    cin>>y;
    } while(y!=1&&y!=2);
    if(y==1){continue;}
    if(y==2){break;}
    
    }   
    
    }
I have done this exercise time ago. the problem is that it is written in Italian :)

is not perfect but it works.
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*******************************************************************************
 *******************************************************************************
 **                                                                           **
 **                   programma 'numeri in lettere'                           **
 **                                                                           **
 *******************************************************************************
 **                                                                           **
 ** questo programma legge un numero MINORE di 10.000 e lo scrive in lettere  **
 **                                                                           **
 *******************************************************************************
 *******************************************************************************/

#include <iostream>

#include <string>

#include <assert.h>

using namespace std;

int numero,migliaia,centinaia,decine,unita;

/*******************************************************************************
 **************************** funzione scompositrice ***************************
 ** NOME: scompositrice (funzione con variabile parametrica)                  **
 ** DESCRIZIONE: la procedura deframmenta un numero inferiore a 10.000, in    **
 **              migliaia,centinaia,decine ed unità                           **
 ** PARAMETRI: si utilizza un parametro riferimento alla variabile 'numero'   **
 ** RISULTATI: il valore nominale di migliaia,centinai,decine ed unità        **
 ** NOTE: la funzione può essere migliorata                                   **
 *******************************************************************************/

int scompositrice(int& num)
{
    migliaia=0;
    
    centinaia=0;
    
    decine=0;
    
    unita=0;
    
    migliaia=num/1000;
    
    int c=num%1000;
    
    centinaia=c/100;
    
    int d=c%100;
    
    decine=d/10;
    
    unita=d%10;
    
    return (c);
    
}
    
/************************************************* START PROGRAM **************************************************/

int main()
{
    while (true)
    {
    numero=0;
    cout<<"inserisci un numero intero da leggere, compreso tra 0 e 9999: "<<'\n';
    cin>>numero;
    if ((numero>9999)||(numero<0))
        {
            cout<<"numero fuori range. statte buenu. ciao";
            break;
          }
    scompositrice(numero);
    if (numero==0)
        cout<<"zero"<<'\n';
    else
    {    
    switch (migliaia)
    {
        case 1:
            cout<<"mille";
            break;
        case 2:
            cout<<"duemila";
            break;
        case 3:
            cout<<"tremila";
            break;
        case 4:
            cout<<"quattromila";
            break;
        case 5:
            cout<<"cinquemila";
            break;
        case 6:
            cout<<"seimila";
            break;
        case 7:
            cout<<"settemila";
            break;
        case 8:
            cout<<"ottomila";
            break;
        case 9:
            cout<<"novemila";
            break;
        default:
            break;
    }
    switch (centinaia)
    {
        case 1:
        cout<<"cento";
            break;
        case 2:
            cout<<"duecento";
            break;
        case 3:
            cout<<"trecento";
            break;
        case 4:
            cout<<"quattrocento";
            break;
        case 5:
            cout<<"cinquecento";
            break;
        case 6:
            cout<<"seicento";
            break;
        case 7:
            cout<<"settecento";
            break;
        case 8:
            cout<<"ottocento";
            break;
        case 9:
            cout<<"novecento";
            break;
        case 0:
        default:
            break;
    }
    switch (decine)
    {
        case 1:
        {
            switch (unita)
            {
                case 0:
                    cout<<"dieci";
                    break;
                case 1:
                    cout<<"undici";
                    break;
                case 2:
                    cout<<"dodici";
                    break;
                case 3:
                    cout<<"tredici";
                    break;
                case 4:
                    cout<<"quattordici";
                    break;
                case 5:
                    cout<<"quindici";
                    break;
                case 6:
                    cout<<"sedici";
                    break;
                case 7:
                    cout<<"diciassette";
                    break;
                case 8:
                    cout<<"diciotto";
                    break;
                case 9:
                    cout<<"diciannove";
                    break;
                default:
                    break;
            }
            break;
       }
        case 2:
           { 
                if ((unita==1)||(unita==8))
                {
                    cout<<"vent";
                 }
                else
                    cout<<"venti";
            }
            break;
        case 3:
            {
                if ((unita==1)||(unita==8))
                {
                    cout<<"trent";
                }
                else
                    cout<<"trenta";
            }
            break;
        case 4:
            {
                if ((unita==1)||(unita==8))
                {
                    cout<<"quarant";
                }
                else
                    cout<<"quaranta";
            }
            break;
        case 5:
            {
                if ((unita==1)||(unita==8))
                {
                    cout<<"cinquant";
                }
                else
                    cout<<"cinquanta";
            }
            break;
        case 6:
            {
                if ((unita==1)||(unita==8))
                {
                    cout<<"sessant";
                }
                else
                    cout<<"sessanta";
            }
            break;
        case 7:
            {
                if ((unita==1)||(unita==8))
                {
                    cout<<"settant";
                }
                else
                    cout<<"settanta";
            }
            break;
        case 8:
            {
                if ((unita==1)||(unita==8))
                {
                    cout<<"ottant";
                }
                else
                    cout<<"ottanta";
            }
            break;
        case 9:
            {
                if ((unita==1)||(unita==8))
                {
                    cout<<"novant";
                }
                else
                    cout<<"novanta";
            }
            break;
        case 0:
        default:
            break;
        }
    if ((decine!=1)&&(unita!=0))
    {
        switch (unita)
        {
            case 1:
                cout<<"uno";
                break;
            case 2:
                cout<<"due";
                break;
            case 3:
                cout<<"tre";
                break;
            case 4:
                cout<<"quattro";
                break;
            case 5:
                cout<<"cinque";
                break;
            case 6:
                cout<<"sei";
                break;
            case 7:
                cout<<"sette";
                break;
            case 8:
                cout<<"otto";
                break;
            case 9:
                cout<<"nove";
                break;
            case 0:
                cout<<"zero";
            default:
                break;
        }
    }
    cout<<'\n';
    }
   }
    return 0;
}

Last edited on
Think about all the stuff that is fluff and get rid of it. In the end you should have two types of tokens:

- a number, representing zero through nine in the ones, tens, or hundreds place
- a power, like "thousand" or "million"

Good luck!
closed account (1v5E3TCk)
thanks for answer but i dont want a program converts numbers to letters. i want a program which gives the number when you input letters
sorry for my english again
lol :)

sorry
closed account (1v5E3TCk)
it is not a problem but i eally need help /:
however, what you wrote on your surce code, is just the opposite of what you say. that's why I entered my code. to do what you want, you should assign a value to each letter or assign the kind words ("hundred") at No. 100.
you could use a vector and a char "type casting" to force the char with int ... but I've never tried ..
Last edited on
closed account (1v5E3TCk)
thank you for reply but i dont know what is a vector ):
i think about code like that:
1
2
3
4
string letter;
          long long number=0;
          cin>>string;
          if(string == "hundred"){number = number+100}


but i dont know how can i break the letter into pieces. i mean when user input one hundred twenty-one how can i break it into pieces like "hundred" "twenty" and "one"
I gave you an answer but you didn't read carefully.

"one hundred twelve"

break this up into the constituent tokens and process them one at a time, grouping by threes:

"one" (a digit)-->+1
"hundred" (a power)-->*100
"twelve" (a pair of digits)-->+12

(1*100)+12 = 112

Another example:

"fourty-five thousand and seventy-three"

"fourty" (digit) --> +40
"five" (digit) --> +5
"thousand" (power)
We pause here to assemble our number (40 + 5 = 45) * 1000 = 45000. Add this 'group by three' number to our final total: 0 + 45000 = 45000.

Continuing:
"seventy" (digit) --> +70
"three" (digit) --> +3
That's the end, so assemble our 'group by three' number: 70 + 3 = 73. Add it to the final total: 45000 + 73 = 45073.

Hope this helps.
closed account (1v5E3TCk)
I have just seen your reply it is a really help full commend i will start to work on it after finishing my checkers game thank you.
Topic archived. No new replies allowed.