Hi everyone!
I just started my first year in C++ programming, and I'm having a little bit of an issue with my code.
If you guys would kindly look it over and provide some pointers, that would be really great!
Im supposed to write a program that translates between normal Arabic numbers to Roman numeral. The program has to ask the user which system they would like to translate a year to by selecting "A" for arabic, "R" for Roman and "X" to exit the program.
when selecting Roman, they would be able to choose between 1000-3000.
When translating to Arabic, the user can choose between I, V, X, L, C, D, M ( 1, 5, 10, 50, 100, 500, 1000)
The program has to loop to let the user perform multiple calculations.
Thanks in advance!
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
|
#include <iostream>
using namespace std;
int main() {
int k, h, t, o, x;
cin >> x;
if (x > 3000) {
return 0;
}
t = x / 1000;
if (t >= 1) {
while (t > 0) {
cout << "M";
t--;
}
}
else
return 0;
x = x % 1000;
h = x / 100;
if (h == 9)
cout << "CM";
else if (h == 4)
cout << "CD";
else if (h >= 5) {
cout << "D";
h = h - 5;
while (h <= 3 && h > 0) {
cout << "C";
h--;
}
}
else if (h > 0) {
while (h <= 3 && h > 0) {
cout << "C";
h--;
}
}
x = x % 100;
t = x / 10;
if (t == 9)
cout << "XC";
else if (t == 4)
cout << "CL";
else if (t >= 5) {
cout << "L";
t = t - 5;
while (t <= 3 && t > 0) {
cout << "X";
t--;
}
}
else if (t > 0) {
while (t <= 3 && t > 0) {
cout << "X";
t--;
}
}
x = x % 10;
o = x / 1;
if (o == 9)
cout << "IX";
else if (o == 4)
cout << "IV";
else if (o >= 5) {
cout << "V";
o = o - 5;
while (o <= 3 && o > 0) {
cout << "I";
o--;
}
}
else if (o > 0) {
while (o <= 3 && o > 0) {
cout << "I";
o--;
}
}
cout << endl;
return 0;
}
|