Writing a Arabic Numeral to Roman Numeral Conversion Program

Hi, I'm new to C++ obviously.

I was given an assignment to write a program where I need to write a program that converts Arabic Numerals into Roman Numerals. I am trying to accomplish this using <string>, while loops,'if else' loops, and extensive use of the division and modulo operators. I am honestly at a loss at how to approach this right now and could use some guidance. I don't expect you all to write a program for me, seeing as this is a lab assignment.

One question I have is this: After I have extracted out all the "places" such as the 1000, 100, 10, and 1, how can I have those values display as their respective Roman Numerals? (ie. M, C, X, I) Would I have those as char constants?

Here is what I have so far:

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
#include <iostream>
#include <climits>
#include <cctype>
#include <string>

using namespace std;

int main(void)
{
    char yesno;
    unsigned short arabic_numeral, divide_thousand, divide_hundred, divide_ten,
                   divide_one, mod_thousand, mod_hundred, mod_ten, mod_one,
                   roman_thousand, roman_hundred, roman_ten, roman_one;
    
    cout <<"\t\tWelcome to the Roman Numeral Program!\n";
    cout <<"\nWould you like to convert numbers to Roman numerals today?\n";
    cin >> yesno;
    cin.ignore (INT_MAX, '\n');
    
    //Allow user option to repeat the program as desired
    while ('Y' == toupper(yesno) )
    {
        cout <<"\n\nPlease enter the number you would like to convert\n";
        cin >> arabic_numeral;
        
        divide_thousand = arabic_numeral / 1000;
        mod_thousand = arabic_numeral % 1000;
        divide_hundred = mod_thousand / 100;
        mod_hundred = mod_thousand % 100;
        divide_ten = mod_hundred / 10;
        mod_ten = mod_hundred % 10;
        divide_one = mod_ten / 1;
        mod_one = mod_ten % 1;
        
        roman_thousand = 1000 * divide_thousand;
        roman_hundred = 100 * divide_hundred;
        roman_ten = 10 * divide_ten;
        roman_one = 1 * divide_one;
        
        
        cout <<""<<roman_thousand<<", "<<roman_hundred<<", "<<roman_ten<<", "
             <<roman_one<<"\n\n";
        
        
        cout <<"\nWould you like to convert any more numbers to Roman
             <<"numerals?\n;
        cin >> yesno;
        cin.ignore (INT_MAX, '\n');
    }
    if ('N' == toupper(yesno) )
    {
        cout <<"Thank you for using the Roman Numeral Conversion Program! Have";
             <<"a great day!\n";
    }
    
    return 0;
}
You need to revise your code. You are assuming that the person will input a number that is 4 digits long.

Anyway, you need to make a loop that will print the letter the 'x' number of times, where 'x' is the digit corresponding to the letter. For example, if your number is 1234, you need to make loops that will print M (1 times), C (2 times), X (3 times) and I (4 times). It should be fairly easy for you to be able to figure out how to tell the program to print a letter 'n' times and calculate 'n'.
Topic archived. No new replies allowed.