#include #include #include //for class string using namespace std; //Convert an integer to a Roman numeral. int main() { cout << "Please input an integer in the range 1 to 3999 inclusive: "; int number {0}; cin >> number; //if user inputs 1234, will become 234, 34, 4 if (!cin) { cerr << "Sorry, unable to input the integer.\n"; return EXIT_FAILURE; } if (number < 1 || number > 3999) { cerr << "Sorry, " << number << " is out of range.\n"; return EXIT_FAILURE; } string a[][10] { {"", "M", "MM", "MMM" }, //thousands {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, //hundreds {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, //tens {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"} //ones }; int n {size(a)}; //number of rows int power {1000}; //will become 100, 10, 1 for (int row {0}; row < n; ++row) { //row is in range 0 to 3 inclusive int col {number/power}; //col is in range 0 to 9 inclusive cout << a[row][col]; number %= power; //means number = number % power power /= 10; //means power = power / 10 } cout << "\n"; return EXIT_SUCCESS; }