Roman to decimal code

Hi, so I know there's several forums covering roman numeral conversions out there but I'm in a intro c++ class and I have to write a code that does it with out any super fancy pre-written functions. (I got in trouble for that). So I have to do it the long, drawn out way. I'm quite on lost on how to do this and all my future labs depend on this working. So anyways, I have to use separate user-defined functions for each task in the code. Here's what I got 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string>

using namespace std;

void roman_input( string &rom_in )
{

     int n = 0;

     while ( n == 0 )
     {
           cout << "Enter a roman numeral: ";
           getline( cin, rom_in );

           for ( int i = 0; i < rom_in.length(); i++ )
           {
                      if ( rom_in.at(i) == 'I' )
                           n = 1;
                      else if ( rom_in.at(i) == 'V' )
                           n = 1;
                      else if ( rom_in.at(i) == 'X' )
                           n = 1; 
                      else if ( rom_in.at(i) == 'L' )
                           n = 1;
                      else if ( rom_in.at(i) == 'C' )
                           n = 1;
                      else if ( rom_in.at(i) == 'D' )
                           n = 1;
                      else if ( rom_in.at(i) == 'M' )
                           n = 1;
                      else
                      {
                           n = 0;
                           cout << "Nope, try again!" << endl;
                           break;
                      }
           }
}

string rom_to_dec( string dec_out )
{
     for ( int i = 0; i < dec_out.length(); i++ )
     {
          if ( dec_out.at(i) == 'I' )
                dec_out.at(i) = 1;
          else if ( dec_out.at(i) == 'V' )
                dec_out.at(i) = 5;
          else if ( dec_out.at(i) == 'X' )
                dec_out.at(i) = 10;
          else if ( dec_out.at(i) == 'L' )
                dec_out.at(i) = 50;
          else if ( dec_out.at(i) == 'C' )
                dec_out.at(i) = 100;
          else if ( dec_out.at(i) == 'D' )
                dec_out.at(i) = 500;
          else if ( dec_out.at(i) == 'M' )
                dec_out.at(i) = 1000;
     }
     return dec_out;
}

int main()
{
     string input;

     roman_input( input );
     cout << input << endl;

     rom_to_dec( input );
     cout << input << endl;

     return 0;
}


It produces the error if the roman numerals aren't uppercase or correct roman numerals and re-prompts for a correct roman numeral, and, it prints the roman numeral that is entered. The conversion part is not working though. Any help with this annoying code would be greatly appreciated.
Which "conversion part is not working", to be precise?
So far I've only made it to the roman to decimal conversion. I suppose I'm really not sure wether its the conversion, string rom_to_dec( string dec_out ), or my function call in main that's not working. A lot of the examples for making this conversion certainly are much more involved than what I have at this point. I set myself back a few codes ago by using a pre-defined function to handle strings and now It's really hurting me not knowing how to write out code myself. So now I'm just extremely focused on trying to figure out how to write out such a code myself. I tried using arrays on one attempt and I got all kinds of errors about improper uses of pointers but I didn't even use pointers, that I know of anyway. I don't know, every day I'm a little more lost and clueless. I don't expect to get anyone to write out code for me, I just need direction/guidance on this stuff so I can maybe have a chance on getting through computer science. Thanks again for any and all assistance in this matter. :)
Topic archived. No new replies allowed.