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
|
/*Write a program that displays the roman numeral equivalent of any decimal number
between 1 and 20 that the user enters. The roman numerals should be stored in an array of
strings and the decimal number that the user enters should be used to locate the array element
holding the roman numeral equivalent. The program should have a loop that allows
the user to continue entering numbers until an end sentinel of 0 is entered.
Input validation: Do not accept scores less than 0 or greater than 20.*/
#include <iostream>
#include <string>
using namespace std;
int main()
{
int user_input;
string ROMAN_NUM[20] = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X",
"XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX"};
do
{
cout << "Enter a number between 1-20. I will convert it to roman numerals." << endl;
cin >> user_input;
while (user_input < 1 || user_input > 20)
{
cout << "BETWEEN 1-20." << endl;
cout << "Enter a number between 1-20. I will convert it to roman numerals." << endl;
}
cout << "Roman numeral form of " << user_input << " is: " << ROMAN_NUM[user_input - 1] << endl;
//"- 1" because the array pulls from 0 first, and the lowest number the user can enter is 1.
return 0;
}
}
|