title: C++ Arabic numbers to Roman Numeral's & vice versa
body: <p>I am writing a C++ program that converts between Arabic and Roman numbering systems. I wrote one program that converts Arabic to Roman and have another program that converts Roman to Arabic. 
  The problem is that I can't figure out how to merge them into one single program so that the user can input an Arabic or Roman number and as a result, the program would convert said number to the other. </p>
  
  <p>My question is HOW can I merge these two programs into one?</p>
  
  <p>Code for Roman to Arabic</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int main()
  {
      char roman_Numeral;
      int arabic_Numeral = 0;
  
      cout &lt;&lt; "Enter the Roman Numeral in Capital letters (e.g. CCXIX) : ";
      while (cin.get(roman_Numeral))
      {
  
          if (arabic_Numeral &gt; 100)
          {
              cout &lt;&lt; "\nInvalid Value. Number must be  between I and C" &lt;&lt; endl;
              return 0;
          }
  
          else if (roman_Numeral == 'C')
          {
              roman_Numeral = cin.peek();
              if (roman_Numeral == 'M' || roman_Numeral == 'D')
              {
                  arabic_Numeral = arabic_Numeral - 100;
              }
              else
              {
                  arabic_Numeral = arabic_Numeral + 100;
              }
  
          }
  
          else if (roman_Numeral == 'L')
          {
              roman_Numeral = cin.peek();
              if (roman_Numeral == 'M' || roman_Numeral == 'D'
                      || roman_Numeral == 'C')
              {
                  arabic_Numeral = arabic_Numeral - 50;
                  continue;
              }
              else
              {
                  arabic_Numeral = arabic_Numeral + 50;
                  continue;
              }
          }
  
          else if (roman_Numeral == 'X')
          {
              roman_Numeral = cin.peek();
              if (roman_Numeral == 'M' || roman_Numeral == 'D'
                      || roman_Numeral == 'C' || roman_Numeral == 'L')
              {
                  arabic_Numeral = arabic_Numeral - 10;
                  continue;
              }
              else
              {
                  arabic_Numeral = arabic_Numeral + 10;
                  continue;
              }
          }
  
          else if (roman_Numeral == 'V')
          {
              roman_Numeral = cin.peek();
              if (roman_Numeral == 'M' || roman_Numeral == 'D'
                      || roman_Numeral == 'C' || roman_Numeral == 'L'
                      || roman_Numeral == 'X')
              {
                  arabic_Numeral = arabic_Numeral - 5;
                  continue;
              }
              else
              {
                  arabic_Numeral = arabic_Numeral + 5;
                  continue;
              }
          }
  
          else if (roman_Numeral == 'I')
          {
              roman_Numeral = cin.peek();
              if (roman_Numeral == 'M' || roman_Numeral == 'D'
                      || roman_Numeral == 'C' || roman_Numeral == 'L'
                      || roman_Numeral == 'X' || roman_Numeral == 'V')
              {
                  arabic_Numeral = arabic_Numeral - 1;
                  continue;
              }
              else
              {
                  arabic_Numeral = arabic_Numeral + 1;
                  continue;
              }
          }
  
          else
              break;
      }
      cout &lt;&lt; arabic_Numeral &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>Code for Arabic to Roman </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  #include &lt;iomanip&gt;
  using namespace std;
  
  #define MAX_INPUT 100 // These constants hold high and low integer numbers,
  #define MIN_INPUT 1
  #define ARRAY_SIZE 4   // and the array size declarator.
  
  string convert(int digit, string low, string mid, string high);
  
  int main()
  {
      string answers[ARRAY_SIZE] = { "", "", "", "" }; //An  array of string to hold the output from the convert function.
      int accumulator = 0; // Variable to hold number of arabic numbers converted.
      int userNum = 0;
      string strUserNum;
  
      do
      {
          cout &lt;&lt; "";
          cout &lt;&lt; "Enter an arabic number between 1 and 100: ";
          cin &gt;&gt; strUserNum;
  
          userNum = std::stoi(strUserNum);
  
          if (userNum == 0 || userNum &gt; MAX_INPUT)
          {
              cout &lt;&lt; "\nInvalid Value. Number must be between 1 and 100" &lt;&lt; endl;
              return 0;
          }
          else if (userNum == 'end')
          {
              cout &lt;&lt; "Exiting program:";
              break;
          }
  
          int thous = userNum / 1000;
  
          int hund = userNum % 1000 / 100;
  
          int tens = userNum % 100 / 10;
  
          int ones = userNum % 10 / 1;
  
          answers[0] = convert(thous, "M", "M", "M");
          answers[1] = convert(hund, "C", "D", "M");
  
          answers[2] = convert(tens, "X", "L", "C");
          answers[3] = convert(ones, "I", "V", "X");
  
          cout &lt;&lt; answers[0] &lt;&lt; answers[1] &lt;&lt; answers[2];
          cout &lt;&lt; answers[3] &lt;&lt; endl;
          cout &lt;&lt; endl;
          break;
  
      } while (userNum != 'end');
  
      system("PAUSE");
      return 0;
  
  }
  string convert(int digit, string low, string mid, string high)
  {
  
      if (digit == 1)
      {
          return low;
      }
      if (digit == 2)
      {
          return low + low;
      }
      if (digit == 3)
      {
          return low + low + low;
      }
      if (digit == 4)
      {
          return low + mid;
      }
      if (digit == 5)
      {
          return mid;
      }
      if (digit == 6)
      {
          return mid + low;
      }
      if (digit == 7)
      {
          return mid + low + low;
      }
      if (digit == 8)
      {
          return mid + low + low + low;
      }
      if (digit == 9)
      {
          return low + high;
      }
      if (digit == 0)
      {
          return "";
      }
  }
  </code></pre>