Задание преобразовать числа в слова, чтобы если пользователь вводит число 10 - то выводилось "Numx is equal to 'ten'"
Но я не могу понять как это все сделать
Можно ли как то писать в
if так, чтобы было несколько условий, чтобы он сразу проверял (num1 ==0 or num2==0 or num3==0 or num4==0 or num5==0), и после этого запускался цикл в которм уже выявлялось какой из numx==0, и как это реализовать в коде?
Надеюсь я доступно объснил что хочу
Заранее благодарю за помощь!
Кликните здесь для просмотра всего текста
C++ |
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
| // Программа "Numbers-Words" - преобразует введенные цифры в слова
//
#include "stdafx.h"
#include "../../../../../std_lib_facilities.h"
int main()
{
int num1, num2, num3, num4, num5;
cout << "Enter 5 numbers from 0 to 20\n";
cout << "Enter num1: ";
cin >> num1;
cout << "Enter num2: ";
cin >> num2;
cout << "Enter num3: ";
cin >> num3;
cout << "Enter num4: ";
cin >> num4;
cout << "Enter num5: ";
cin >> num5;
if (num1 == 0)
{
cout << "Num1 is equal to 'zero'!\n";
if (num2 == 0)
cout << "Num2 is equal to 'zero'!\n";
else if (num3 == 0)
cout << "Num3 is equal to 'zero'!\n";
else if (num4 == 0)
cout << "Num4 is equal to 'zero'!\n";
else
cout << "Num5 is equal to 'zero'!\n";
}
keep_window_open();
return 0;
} |
|
Добавлено через 6 минут
Вроде нашел как использовать то что я хотел, но она все равно работает не корректно, выполняет первую проверку и выходит с цикца
Кликните здесь для просмотра всего текста
C++ |
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
| // Программа "Numbers-Words" - преобразует введенные цифры в слова
//
#include "stdafx.h"
#include "../../../../../std_lib_facilities.h"
int main()
{
int num1, num2, num3, num4, num5;
cout << "Enter 5 numbers from 0 to 20\n";
cout << "Enter num1: ";
cin >> num1;
cout << "Enter num2: ";
cin >> num2;
cout << "Enter num3: ";
cin >> num3;
cout << "Enter num4: ";
cin >> num4;
cout << "Enter num5: ";
cin >> num5;
if ( num1 == 0 || num2 == 0 || num3 == 0 || num4 == 0 || num5 == 0 )
{
if (num1 == 0)
cout << "Num1 is equal to 'zero'!\n";
else if (num2 == 0)
cout << "Num2 is equal to 'zero'!\n";
else if (num3 == 0)
cout << "Num3 is equal to 'zero'!\n";
else if (num4 == 0)
cout << "Num4 is equal to 'zero'!\n";
else
cout << "Num5 is equal to 'zero'!\n";
}
keep_window_open();
return 0;
} |
|
Добавлено через 19 минут
Кликните здесь для просмотра всего текста
C++ |
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
312
313
314
315
316
317
318
319
| // Программа "Numbers-Words" - преобразует введенные цифры в слова
//
#include "stdafx.h"
#include "../../../../../std_lib_facilities.h"
int main()
{
int num1, num2, num3, num4, num5;
cout << "Enter 5 numbers from 0 to 20\n";
cout << "Enter num1: ";
cin >> num1;
cout << "Enter num2: ";
cin >> num2;
cout << "Enter num3: ";
cin >> num3;
cout << "Enter num4: ";
cin >> num4;
cout << "Enter num5: ";
cin >> num5;
if ( num1 == 0 || num2 == 0 || num3 == 0 || num4 == 0 || num5 == 0 ) // Проверка на введение : 0
{
if (num1 == 0)
cout << "Num1 is equal to 'zero'!\n";
if (num2 == 0)
cout << "Num2 is equal to 'zero'!\n";
if (num3 == 0)
cout << "Num3 is equal to 'zero'!\n";
if (num4 == 0)
cout << "Num4 is equal to 'zero'!\n";
if (num5 == 0)
cout << "Num5 is equal to 'zero'!\n";
}
if (num1 == 1 || num2 == 1 || num3 == 1 || num4 == 1 || num5 == 1) // Проверка на введение : 1
{
if (num1 == 1)
cout << "Num1 is equal to 'one'!\n";
if (num2 == 1)
cout << "Num2 is equal to 'one'!\n";
if (num3 == 1)
cout << "Num3 is equal to 'one'!\n";
if (num4 == 1)
cout << "Num4 is equal to 'one'!\n";
if (num5 == 1)
cout << "Num5 is equal to 'one'!\n";
}
if (num1 == 2 || num2 == 2 || num3 == 2 || num4 == 2 || num5 == 2) // Проверка на введение : 2
{
if (num1 == 2)
cout << "Num1 is equal to 'two'!\n";
if (num2 == 2)
cout << "Num2 is equal to 'two'!\n";
if (num3 == 2)
cout << "Num3 is equal to 'two'!\n";
if (num4 == 2)
cout << "Num4 is equal to 'two'!\n";
if (num5 == 2)
cout << "Num5 is equal to 'two'!\n";
}
if (num1 == 3 || num2 == 3 || num3 == 3 || num4 == 3 || num5 == 3) // Проверка на введение : 3
{
if (num1 == 3)
cout << "Num1 is equal to 'three'!\n";
if (num2 == 3)
cout << "Num2 is equal to 'three'!\n";
if (num3 == 3)
cout << "Num3 is equal to 'three'!\n";
if (num4 == 3)
cout << "Num4 is equal to 'three'!\n";
if (num5 == 3)
cout << "Num5 is equal to 'three'!\n";
}
if (num1 == 4 || num2 == 4 || num3 == 4 || num4 == 4 || num5 == 4) // Проверка на введение : 4
{
if (num1 == 4)
cout << "Num1 is equal to 'four'!\n";
if (num2 == 4)
cout << "Num2 is equal to 'four'!\n";
if (num3 == 4)
cout << "Num3 is equal to 'four'!\n";
if (num4 == 4)
cout << "Num4 is equal to 'four'!\n";
if (num5 == 4)
cout << "Num5 is equal to 'four'!\n";
}
if (num1 == 5 || num2 == 5 || num3 == 5 || num4 == 5 || num5 == 5) // Проверка на введение : 5
{
if (num1 == 5)
cout << "Num1 is equal to 'five'!\n";
if (num2 == 5)
cout << "Num2 is equal to 'five'!\n";
if (num3 == 5)
cout << "Num3 is equal to 'five'!\n";
if (num4 == 5)
cout << "Num4 is equal to 'five'!\n";
if (num5 == 5)
cout << "Num5 is equal to 'five'!\n";
}
if (num1 == 6 || num2 == 6 || num3 == 6 || num4 == 6 || num5 == 6) // Проверка на введение : 6
{
if (num1 == 6)
cout << "Num1 is equal to 'six'!\n";
if (num2 == 6)
cout << "Num2 is equal to 'six'!\n";
if (num3 == 6)
cout << "Num3 is equal to 'six'!\n";
if (num4 == 6)
cout << "Num4 is equal to 'six'!\n";
if (num5 == 6)
cout << "Num5 is equal to 'six'!\n";
}
if (num1 == 7 || num2 == 7 || num3 == 7 || num4 == 7 || num5 == 7) // Проверка на введение : 7
{
if (num1 == 7)
cout << "Num1 is equal to 'seven'!\n";
if (num2 == 7)
cout << "Num2 is equal to 'seven'!\n";
if (num3 == 7)
cout << "Num3 is equal to 'seven'!\n";
if (num4 == 7)
cout << "Num4 is equal to 'seven'!\n";
if (num5 == 7)
cout << "Num5 is equal to 'seven'!\n";
}
if (num1 == 8 || num2 == 8 || num3 == 8 || num4 == 8 || num5 == 8) // Проверка на введение : 8
{
if (num1 == 8)
cout << "Num1 is equal to 'eight'!\n";
if (num2 == 8)
cout << "Num2 is equal to 'eight'!\n";
if (num3 == 8)
cout << "Num3 is equal to 'eight'!\n";
if (num4 == 8)
cout << "Num4 is equal to 'eight'!\n";
if (num5 == 8)
cout << "Num5 is equal to 'eight'!\n";
}
if (num1 == 9 || num2 == 9 || num3 == 9 || num4 == 9 || num5 == 9) // Проверка на введение : 9
{
if (num1 == 9)
cout << "Num1 is equal to 'nine'!\n";
if (num2 == 9)
cout << "Num2 is equal to 'nine'!\n";
if (num3 == 9)
cout << "Num3 is equal to 'nine'!\n";
if (num4 == 9)
cout << "Num4 is equal to 'nine'!\n";
if (num5 == 9)
cout << "Num5 is equal to 'nine'!\n";
}
if (num1 == 10 || num2 == 10 || num3 == 10 || num4 == 10 || num5 == 10) // Проверка на введение : 10
{
if (num1 == 10)
cout << "Num1 is equal to 'ten'!\n";
if (num2 == 10)
cout << "Num2 is equal to 'ten'!\n";
if (num3 == 10)
cout << "Num3 is equal to 'ten'!\n";
if (num4 == 10)
cout << "Num4 is equal to 'ten'!\n";
if (num5 == 10)
cout << "Num5 is equal to 'ten'!\n";
}
if (num1 == 11 || num2 == 11 || num3 == 11 || num4 == 11 || num5 == 11) // Проверка на введение : 11
{
if (num1 == 11)
cout << "Num1 is equal to 'eleven'!\n";
if (num2 == 11)
cout << "Num2 is equal to 'eleven'!\n";
if (num3 == 11)
cout << "Num3 is equal to 'eleven'!\n";
if (num4 == 11)
cout << "Num4 is equal to 'eleven'!\n";
if (num5 == 11)
cout << "Num5 is equal to 'eleven'!\n";
}
if (num1 == 12 || num2 == 12 || num3 == 12 || num4 == 12 || num5 == 12) // Проверка на введение : 12
{
if (num1 == 12)
cout << "Num1 is equal to 'twelve'!\n";
if (num2 == 12)
cout << "Num2 is equal to 'twelve'!\n";
if (num3 == 12)
cout << "Num3 is equal to 'twelve'!\n";
if (num4 == 12)
cout << "Num4 is equal to 'twelve'!\n";
if (num5 == 12)
cout << "Num5 is equal to 'twelve'!\n";
}
if (num1 == 13 || num2 == 13 || num3 == 13 || num4 == 13 || num5 == 13) // Проверка на введение : 13
{
if (num1 == 13)
cout << "Num1 is equal to 'thirteen'!\n";
if (num2 == 13)
cout << "Num2 is equal to 'thirteen'!\n";
if (num3 == 13)
cout << "Num3 is equal to 'thirteen'!\n";
if (num4 == 13)
cout << "Num4 is equal to 'thirteen'!\n";
if (num5 == 13)
cout << "Num5 is equal to 'thirteen'!\n";
}
if (num1 == 14 || num2 == 14 || num3 == 14 || num4 == 14 || num5 == 14) // Проверка на введение : 14
{
if (num1 == 14)
cout << "Num1 is equal to 'fourteen'!\n";
if (num2 == 14)
cout << "Num2 is equal to 'fourteen'!\n";
if (num3 == 14)
cout << "Num3 is equal to 'fourteen'!\n";
if (num4 == 14)
cout << "Num4 is equal to 'fourteen'!\n";
if (num5 == 14)
cout << "Num5 is equal to 'fourteen'!\n";
}
if (num1 == 15 || num2 == 15 || num3 == 15 || num4 == 15 || num5 == 15) // Проверка на введение : 15
{
if (num1 == 15)
cout << "Num1 is equal to 'fifteen'!\n";
if (num2 == 15)
cout << "Num2 is equal to 'fifteen'!\n";
if (num3 == 15)
cout << "Num3 is equal to 'fifteen'!\n";
if (num4 == 15)
cout << "Num4 is equal to 'fifteen'!\n";
if (num5 == 15)
cout << "Num5 is equal to 'fifteen'!\n";
}
if (num1 == 16 || num2 == 16 || num3 == 16 || num4 == 16 || num5 == 16) // Проверка на введение : 16
{
if (num1 == 16)
cout << "Num1 is equal to 'sixteen'!\n";
if (num2 == 16)
cout << "Num2 is equal to 'sixteen'!\n";
if (num3 == 16)
cout << "Num3 is equal to 'sixteen'!\n";
if (num4 == 16)
cout << "Num4 is equal to 'sixteen'!\n";
if (num5 == 16)
cout << "Num5 is equal to 'sixteen'!\n";
}
if (num1 == 17 || num2 == 17 || num3 == 17 || num4 == 17 || num5 == 17) // Проверка на введение : 17
{
if (num1 == 17)
cout << "Num1 is equal to 'seventeen'!\n";
if (num2 == 17)
cout << "Num2 is equal to 'seventeen'!\n";
if (num3 == 17)
cout << "Num3 is equal to 'seventeen'!\n";
if (num4 == 17)
cout << "Num4 is equal to 'seventeen'!\n";
if (num5 == 17)
cout << "Num5 is equal to 'seventeen'!\n";
}
if (num1 == 18 || num2 == 18 || num3 == 18 || num4 == 18 || num5 == 18) // Проверка на введение : 18
{
if (num1 == 18)
cout << "Num1 is equal to 'eighteen'!\n";
if (num2 == 18)
cout << "Num2 is equal to 'eighteen'!\n";
if (num3 == 18)
cout << "Num3 is equal to 'eighteen'!\n";
if (num4 == 18)
cout << "Num4 is equal to 'eighteen'!\n";
if (num5 == 18)
cout << "Num5 is equal to 'eighteen'!\n";
}
if (num1 == 19 || num2 == 19 || num3 == 19 || num4 == 19 || num5 == 19) // Проверка на введение : 19
{
if (num1 == 19)
cout << "Num1 is equal to 'nineteen'!\n";
if (num2 == 19)
cout << "Num2 is equal to 'nineteen'!\n";
if (num3 == 19)
cout << "Num3 is equal to 'nineteen'!\n";
if (num4 == 19)
cout << "Num4 is equal to 'nineteen'!\n";
if (num5 == 19)
cout << "Num5 is equal to 'nineteen'!\n";
}
if (num1 == 20 || num2 == 20 || num3 == 20 || num4 == 20 || num5 == 20) // Проверка на введение : 20
{
if (num1 == 20)
cout << "Num1 is equal to 'twenty'!\n";
if (num2 == 20)
cout << "Num2 is equal to 'twenty'!\n";
if (num3 == 20)
cout << "Num3 is equal to 'twenty'!\n";
if (num4 == 20)
cout << "Num4 is equal to 'twenty'!\n";
if (num5 == 20)
cout << "Num5 is equal to 'twenty'!\n";
}
keep_window_open();
return 0;
} |
|
Я тут что то наделал, вроде все работает, но код получился очень большим, наверное надо было использовать какой то другой способ