Roman Numeral Converter???

I have to write a program that converts numbers into roman numerals, but I'm not really sure where to go from what I have now. Anyone know how I can finish this? Im very new to this and I'm completely lost in class :(
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include<iostream>
#include<climits>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<string>

using namespace std;

int main(void)

{
    string romnum;
    unsigned short number;
    short M;  // Numerical Value 1000
    short D;  // Numerical Value 500
    short C;  // Numerical Value 100
    short L;  // Numerical Value 50
    short X;  // Numerical Value 10
    short IX; // Numerical Value 9
    short V;  // Numerical Value 5
    short IV; // Numerical Value 4
    short I; // Numerical Value 1

    char yes_no

          
    cout << "\nWould you like to convert numbers into Roman Numerals?";
    cin >> yes_no;
    cin.ignore(INT_MAX, '\n');
    while ( toupper(yes_no) == 'Y' )
        
    {

        cout<< "\n\t Excelent! Let's get started!\n";
        
        cout<< "\n\t Please enter your number:\n";
        
        
        
        
        cin >> number;
        if ( number >= 4000 || number <= 0 )
        {
            cout << "\nError.  Please enter a number greater than 0 and less than
                    4000.\n";
        
        }
        else
        {
                
            M = number / 1000;
            number = number % 1000;
            
            D = number / 500;
            number = number % 500;
            
            C = number / 100;
            number = number % 100;
            
            L = number / 50;
            number = number % 50;
            
            X = number / 10;
            number = number % 10;
            
            IX = number / 9;
            number = number % 9; 
            
            V = number / 5;
            number = number % 5;
            
            IV = number / 4;
            number = number % 4;
            
            I = number;
                
            cout << "Thank you.\n";
        }
        
        
    }
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        cout<<"\n\t\tThank you for using the Roman Numeral Converter!!!\n";
        
        cout << "\n\t\t\t\tHAVE A GREAT DAY!!!\n";
    }
    
        return 0;
}
  

short IX; // Numerical Value 9 Is not a base number, not needed
short IV; // Numerical Value 4 Is nor a base number, not needed
line 25 needs something to end the command
Remove void from main... just not needed.
54,57,60,63,66,72, and 75 need something or else the value of number will change

67 and 73 can be deleted.


Here is your hint:
Write a function that takes 2 parameters. Your roman numeral, and your variable number....
Last edited on
I made the small cahnges, but idk what 54,57,60,63,66,72, and 75 need. And I have no idea how to write the function that takes 2 parameters. To be honest I'm not even 100% sure how lines 49-69 work exactly and how to use them later on. My instructor just said to start it like that.

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include<iostream>
#include<climits>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<string>

using namespace std;

int main()

{
    string romnum;
    unsigned short number;
    short M;  // Numerical Value 1000
    short D;  // Numerical Value 500
    short C;  // Numerical Value 100
    short L;  // Numerical Value 50
    short X;  // Numerical Value 10
    short V;  // Numerical Value 5
    short I; // Numerical Value 1
    char yes_no;

          
    cout << "\nWould you like to convert numbers into Roman Numerals?";
    cin >> yes_no;
    cin.ignore(INT_MAX, '\n');
    while ( toupper(yes_no) == 'Y' )
        
    {

        cout<< "\n\t Excelent! Let's get started!\n";
        
        cout<< "\n\t Please enter your number:\n";
        
        
        
        
        cin >> number;
        if ( number >= 4000 || number <= 0 )
        {
            cout << "\nError.  Please enter a number greater than 0 and less than
                    4000.\n";
        
        }
        else
        {
                
            M = number / 1000;
            number = number % 1000;
            
            D = number / 500;
            number = number % 500;
            
            C = number / 100;
            number = number % 100;
            
            L = number / 50;
            number = number % 50;
            
            X = number / 10;
            number = number % 10;
            
            V = number / 5;
            number = number % 5;
            
            I = number;
                
            cout << "Thank you.\n";
        }
        
        
    }
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        cout<<"\n\t\tThank you for using the Roman Numeral Converter!!!\n";
        
        cout << "\n\t\t\t\tHAVE A GREAT DAY!!!\n";
    }
    
        return 0;
}
  
Last edited on
-_-
If anyone else knows how to complete this, please help. I am still lost!
Try this one... https://www.youtube.com/watch?v=-87KQS-rZCA

We like to see people make a good faith effort... TRY to write something
Last edited on
None of that made sense to me. We didn't learn any of that in my class. I can use strings, looping, and branching for this program according to my instructor. So, I still have no idea what to do. Can you show me how I can complete this and explain in detail what you did? Is my original code even correct? Am i going in the right direction?
Sorry if it seems I tried to push you into something you aren't ready for...

without the function, put the 4 and 9 back in then....

Okay, You know looping, and you know strings. We'll do it that way.

You have a string declared... romnum
You have the number of how many X,M,X and so on it will take...
loop for 1 to number
string + the letter

as it moves down the list, it'll add on to the string....
and at the end, print it


can you show me how to do that? I just got an intro to it yesterday. I still don't really know how to apply it to my program. This is extremely frustrating. I've never struggled this much in a class before to the point where I have no idea what is going on. I am losing my mind writing these programs.....@Q$TH#$QGJW#{"OTbjh
Topic archived. No new replies allowed.