Integer conversion

Hi, so my question is this: when I run program I can't get digit_1 to be converted to a word. Why is that? The code is given below.

In other words when I input 31 I can't get the program to say thirty one.
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
#include <iostream>
#include <string>

using namespace std;

string converter(unsigned long a) {
  string decodeI;
  switch(a)
  {
    case 1: decodeI="one";
    break;
    case 2: decodeI="two";
    break;
    case 3: decodeI="three";
    break;
    case 4: decodeI="four";
    break;
    case 5: decodeI="five";
    break;
    case 6: decodeI="six";
    break;
    case 7: decodeI="seven";
    break;
    case 8: decodeI="eight";
    break;
    case 9: decodeI="nine";
    break;
    case 10: decodeI="ten";
    break;
    case 11: decodeI="eleven";
    break;
    case 12: decodeI="twelve";
    break;
    case 13: decodeI="thirteen";
    break;
    case 14: decodeI="fourteen";
    break;
    case 15: decodeI="fifteen";
    break;
    case 16: decodeI="sixteen";
    break;
    case 17: decodeI="seventeen";
    break;
    case 18: decodeI="eighteen";
    break;
    case 19: decodeI="nineteen";
    break;
    case 20: decodeI="twenty";
    break;
    case 30: decodeI="thirty";
    break;
    case 40: decodeI="fourty";
    break;
    case 50: decodeI="fifty";
    break;
    case 60: decodeI="sixty";
    break;
    case 70: decodeI="seventy";
    break;
    case 80: decodeI="eighty";
    break;
    case 90: decodeI="ninety";
    break;
    case 100: decodeI="one hundred";
    break;
    case 1000: decodeI="one thousand";
    break;
    case 1000000: decodeI="one million";
    break;
    case 1000000000: decodeI="one billion";
    break;
  }
  return decodeI;
}

int change_to_tens (int input) {
  int a, b;
  a = input / 10;
  b = a * 10;
  return b;
}

int main() {
  int integer, digit_1, digit_2;
  cout << "Input the integer: ";
  cin >> integer;
  digit_1 = integer % 10;
  if (integer >=1 || integer <=19) {
  cout << converter(integer) << endl;
}
  else if (integer % 10 == 0) {
  cout << converter(integer) << endl;
  }
  else if (integer % 10 != 0) {
  cout << converter(change_to_tens(integer)) << " " << converter(digit_1) << endl;
  }
  return 0;
}
Last edited on
if (integer >=1 || integer <=19) {

Can you think of any value of integer for which this expression would not be true?
Last edited on
@MikeyBoy That's true. Thank you.
Topic archived. No new replies allowed.