forked from Ansi007/Programming-Fundamentals-Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert number into char format
111 lines (90 loc) · 2.1 KB
/
convert number into char format
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
#include<iostream>
using namespace std;
class convert
{
private:
int num;
string* ptr;
string array[51] = { "zero","one","two","three","four","five","six","seven","eight","nine","ten",
"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",
"eighteen","nineteen","twenty","twenty-one","twenty-two","twenty-three",
"twenty-four","twenty-five","twenty-six","twenty-seven","twenty-eight",
"twenty-nine","thirty","thirty-one","thirty-two","thirty-three","thirty-four",
"thirty-five","thirty-six","thirty-seven","thirty-eight","thirty-nine","fourty",
"fourty-one", "fourty-two", "fourty-three", "fourty-four", "fourty-five", "fourty-six",
"fourty-seven", "fourty-eight", "fourty-nine", "fifty"};
string hundred = "hundred";
string thousand = "thousand";
public:
convert();
void setdata(int n);
};
convert::convert()
{
num = 0;
ptr = nullptr;
}
void convert::setdata(int n)
{
num = n;
int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
ptr = array;
if (n / 1000)
{
x1 = n / 1000;
x2 = n % 1000;
x3 = x2 / 100;
x4 = x2 % 100;
int a = x1;
cout << *(ptr + a) << " ";
cout << thousand << " ";
int b = x3;
cout << *(ptr + b) << " ";
if (n / 100)
{
cout << hundred << " ";
}
int c = x4;
cout << *(ptr + c) << " ";
}
else if (n / 100)
{
x1 = num / 100;
x2 = num % 100;
int a = x1;
cout << *(ptr + a) << " ";
if (n / 100)
{
cout << hundred << " ";
}
int b = x2;
cout << *(ptr + b) << " ";
}
else if(n/10)
{
x1 = n / 10;
x2 = n % 10;
int a = x1;
cout << *(ptr + a) << " ";
int b = x2;
cout << *(ptr + b) << " ";
}
}
int main()
{
char yes = 'y';
int p = 0;
do
{
int num;
cout << "CAUTION!! PLEASE ENTER LAST TWO DIGIT LESS THAN OR EQUAL TO FIFTY" << endl;
cout << "enter number : " << "\t";
cin >> num;
cout << "HERE PROGRAM WILL CONVERT NUM INTO HUMAN READABLE FORM" << endl;
convert c1;
c1.setdata(num);
cout << endl;
cout << "do you want to enter again press small y for yes " << "\t";
cin >> yes;
} while (yes == 'y');
}