So far this sort of works I guess however I'm not sure how I would get it to do the IV or VII or whatever. It'll only go either IIIIIIII......, VVVVVVVV...., XXXXXXX...., etc.
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main() {
char response = 'Y';
string roman;
int b;
int x;
string die = "";
int i = 0;
cout << "Enter a number" << endl;
while (response == 'Y') {
cin >> x;
if (x <= 1000 && x > 0) {
cout << "Good" << endl;
if (x == 1000) {
roman += 'M';
}
elseif (x >= 100) {
b = x / 100;
if (b == 9) {
roman += "CM";
}
elseif (b >= 5) {
roman += 'D';
for (int i = 0; i != (b - 5); i++) {
roman += 'C';
}
}
elseif (b == 4) {
roman += "CD";
}
else {
for (int i = 0; i != b; i++) {
roman += 'C';
}
}
x %= 100;
}
if (x < 100 && x >= 10) {
b = x / 10;
if (b == 9) {
roman += "XC";
}
elseif (b >= 5) {
roman += 'L';
for (int i = 0; i != (b - 5); i++) {
roman += 'X';
}
}
elseif (b == 4) {
roman += "XL";
}
else {
for (int i = 0; i != b; i++) {
roman += 'X';
}
}
x %= 10;
}
if (x < 10) {
b = x / 1;
if (x == 9) {
roman += "IX";
}
elseif (x >= 5) {
roman += "V";
for (int i = 0; i != (b - 5); i++) {
roman += 'I';
}
}
elseif (x == 4) {
roman += "IV";
}
else {
for (int i = 0; i != b; i++) {
roman += 'I';
}
}
}
cout << roman << endl;
}
else {
cout << "Not a valid choice " << endl;
cin.clear();
cin.ignore(1000, '\n');
}
cout << "Go again Y for yes: ";
cin >> response;
if (response == 'Y') {
continue;
roman = die;
x = 0;
b = 0;
}
else
response = response;
}
cin >> response;
return 0;
}