-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path35-words.cpp
More file actions
54 lines (38 loc) · 1.31 KB
/
35-words.cpp
File metadata and controls
54 lines (38 loc) · 1.31 KB
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
#include <iostream>
#include <string>
using namespace std;
int main() {
int number;
string result;
string oneToNine[] = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
string tenToNineteen[] = {"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};
string tens[] = {"", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
// enter a number
cout << "Enter a number between 0 and 100: ";
cin >> number;
if (number < 0 || number > 100) {
cout << "Number out of range. Please enter a number between 0 and 100." << endl;
}
if (number == 100) {
result = "One Hundred";
} else if (number >= 20) {
int tensPlace = number / 10;
int unitsPlace = number % 10;
if (tensPlace > 1) {
result += tens[tensPlace];
if (unitsPlace > 0) {
result += " " + oneToNine[unitsPlace];
}
}
} else if (number >= 10) {
result = tenToNineteen[number - 10];
} else {
result = oneToNine[number];
}
if (number == 0) {
result = "Zero";
}
// Print the result
cout << result << endl;
return 0;
}