Pages

Subscribe:

About Template

Random Posts

C++ Program That Converts Roman Numerals to Arabic Numerals


Name:  Roman Numerals to Arabic Numerals Converter
Description of the Program: This program converts Roman Numerals into Arabic Numerals.

As you can see in the screenshot below, I entered the Roman Numeral CMLXLIX which has seven letters. Then, the Arabic Numeral Format 999 displayed. You can only enter 9 letters for any Roman Numeral Format...


 














//Below are the Codes of the Program:

#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <math.h>
int main()
{  int t=0,x[10]={0},f=0;
    char a[10], b[10];
   cout<<"You must type big letters. Just keep on pressing ENTER  \n";
   cout<<"until you get the Arabic Numeral Format.\n";
   cout<<"Example of Roman Numerals:  \n";
   cout<<"                        CMLXLIX  \n";
   cout<<"                        DCLXIX \n";
   cout<<"                        CXLIII \n";
   cout<<"                        MDLV \n";
    cout<<"Enter any Roman Numerals: ";
   for(int i=0; i<10; i++)
   {
    cin.get(a[i]);
    if(a[i]==' ')i=10;
    t++;
   }
    t=t-1;

   for(int i=0; i<t; i++)
   {
   if(a[i]=='M')
   {x[i]=1000;}
   else if(a[i]=='D')
   {x[i]=500;}
   else if(a[i]=='C')
   {x[i]=100;}
   else if(a[i]=='L')
   {x[i]=50;}
   else if(a[i]=='X')
   {x[i]=10;}
   else if(a[i]=='V')
   {x[i]=5;}
   else if(a[i]=='I')
   {x[i]=1;}
   else if(a[i]==' ')
   {x[i]=0;}
   }
     for(int i=0; i<t; i++)
   {
   if(abs(x[i])<abs(x[i+1])&&(i+1)<t)
   {
   x[i]=x[i]*(-1);
   x[i+1]=x[i+1];
   }
   }
   for(int i=0; i<t; i++)
   {
   f=f+x[i];
   }
   cout<< "\nArabic Numeral Format: " << f << endl;

   getch();
   return 0;
   }