Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

roman numeral converter

Posted on 1997-07-11
5
Medium Priority
?
2,890 Views
Last Modified: 2012-05-04
I need a small c++ program to convert roman numerals to decimal. Any takers? Must provide souce...
0
Comment
Question by:datamike
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
ocurance earned 300 total points
ID: 1164783
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
0
 

Expert Comment

by:ocurance
ID: 1164784
Did this answer your question sufficiently?  Are you going to grade this now?
0
 

Author Comment

by:datamike
ID: 1164785
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.
0
 

Expert Comment

by:ocurance
ID: 1164786
Give me your email address and I'll send you the whole program code.
0
 

Author Comment

by:datamike
ID: 1164787
send to: datamike@interaccess.com
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question