-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
178 lines (158 loc) · 5.57 KB
/
main.cpp
File metadata and controls
178 lines (158 loc) · 5.57 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
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
#include <iostream>
#include <string>
int main() {
std::string userInput;
std::string userAnswer;
//getting input
std::cout << "Are you converting from a Roman numeral to a number?" << std::endl;
std::cin >> userAnswer;
int total = 0;
int conversion[userInput.length()];
char letters[userInput.length()];
//roman to number
if (userAnswer == "yes" ){
std::cout << "What is the Roman Numeral?" << std::endl;
std::cin >> userInput;
char romanNumber[userInput.length()];
for (int i = 0; i < userInput.length(); ++i) {
romanNumber[i] = userInput.at(i);
}
//switching character to number
for (int i = 0; i < userInput.length(); ++i) {
if (romanNumber[i] == 'I'){
conversion[i] = 1;
}
else if (romanNumber[i] == 'V'){
conversion[i] = 5;
}
else if (romanNumber[i] == 'X'){
conversion[i] = 10;
}
else if (romanNumber[i] == 'L'){
conversion[i] = 50;
}
else if (romanNumber[i] == 'C'){
conversion[i] = 100;
}
else if (romanNumber[i] == 'D'){
conversion[i] = 500;
}
else if (romanNumber[i] == 'M'){
conversion[i] = 1000;
}
else {
std::cout << "This is not a valid Roman Numeral" << std::endl;
}
std::cout << conversion[i] << ",";
}
//checking if need to subtract
//TODO find a way to add up the multiple numbers to minus (IIIX)
for (int i = 0; i < (userInput.length() - 1); ++i) {
if (conversion[i] < conversion[i + 1]){
std::cout << "ok";
conversion[i] = conversion[i + 1] - conversion[i];
conversion[i + 1] = 0;
}
}
//adding up all the numbers
for (int i = 0; i < userInput.length(); ++i) {
total += conversion[i];
}
std::cout << std::endl;
std::cout << total << std::endl;
}
else if (userAnswer == "no" ){
std::cout << "What is the number?" << std::endl;
std::cin >> userInput;
for (int i = (userInput.length() - 1); i = (userInput.length() - 2); ++i) {
if (userInput.at(i) == 1){
letters[i] = 'I';
}
else if (userInput.at(i) == 2){
letters[i] = 'II';
}
else if (userInput.at(i) == 3){
letters[i] = 'III';
}
else if (userInput.at(i) == 4){
letters[i] = 'IV';
}
else if (userInput.at(i) == 5){
letters[i] = 'V';
}
else if (userInput.at(i) == 6){
letters[i] = 'VI';
}
else if (userInput.at(i) == 7){
letters[i] = 'VII';
}
else if (userInput.at(i) == 8){
letters[i] = 'VIII';
}
else if (userInput.at(i) == 9){
letters[i] = 'IX';
}
}
if(userInput.length() > 1) {
for (int i = (userInput.length() - 2); i < (userInput.length() - 3); ++i) {
if (userInput.at(i) == 1) {
letters[i] = 'X';
} else if (userInput.at(i) == 2) {
letters[i] = 'XX';
} else if (userInput.at(i) == 3) {
letters[i] = 'XXX';
} else if (userInput.at(i) == 4) {
letters[i] = 'XL';
} else if (userInput.at(i) == 5) {
letters[i] = 'L';
} else if (userInput.at(i) == 6) {
letters[i] = 'LX';
} else if (userInput.at(i) == 7) {
letters[i] = 'LXX';
} else if (userInput.at(i) == 8) {
letters[i] = 'LXXX';
} else if (userInput.at(i) == 9) {
letters[i] = 'XC';
}
}
}
if(userInput.length() > 2) {
for (int i = (userInput.length() - 3); i < (userInput.length() - 4); ++i) {
if (userInput.at(i) == 1) {
letters[i] = 'C';
} else if (userInput.at(i) == 2) {
letters[i] = 'CC';
} else if (userInput.at(i) == 3) {
letters[i] = 'CCC';
} else if (userInput.at(i) == 4) {
letters[i] = 'CD';
} else if (userInput.at(i) == 5) {
letters[i] = 'D';
} else if (userInput.at(i) == 6) {
letters[i] = 'DC';
} else if (userInput.at(i) == 7) {
letters[i] = 'DCC';
} else if (userInput.at(i) == 8) {
letters[i] = 'DCCC';
} else if (userInput.at(i) == 9) {
letters[i] = 'CM';
}
}
}
if(userInput.length() > 3) {
for (int i = (userInput.length() - 4); i < (userInput.length() - 5); ++i) {
if (userInput.at(i) == 1) {
letters[i] = 'M';
} else if (userInput.at(i) == 2) {
letters[i] = 'MM';
} else if (userInput.at(i) == 3) {
letters[i] = 'MMM';
}
}
}
for (int i = 0; i < userInput.length(); ++i) {
std::cout << letters[i];
}
}
return 0;
}