We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

roman numeral converter

datamike
datamike asked
on
Medium Priority
2,938 Views
Last Modified: 2012-05-04
I need a small c++ program to convert roman numerals to decimal. Any takers? Must provide souce...
Comment
Watch Question

Commented:
Pass in the char array as a roman numeral, and Roman2Decimal will return the value that you're looking for.

int Roman2Decimal(const char *Roman)
{
   int Total = 0;

   for(int i = 0; i < strlen(Roman); i++)
   {
            if(GetValue(Roman[i]) < GetValue(Roman[i + 1]))
                Total -= GetValue(Roman[i]);
        else
                Total += GetValue(Roman[i]);

       }

    return Total;

}

int GetValue(char numeral)
{
   int value = 0;

   switch(numeral)
   {
      case 'I':
        value = 1;
         break;

      case 'V':
        value = 5;
        break;

      case 'X':
         value = 10;
         break;

     etc.............
   }
   return value;
}



Good Luck,
Roger

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
Did this answer your question sufficiently?  Are you going to grade this now?

Author

Commented:
could you provide an entire c++ program? could you also do it without using pointers? if you can do these tasks, I'll give you an 'a' and an extra 100 points for 250 total.

Commented:
Give me your email address and I'll send you the whole program code.

Author

Commented:
send to: datamike@interaccess.com
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.