Making roman numerals into arabic numbers

This is a discussion on Making roman numerals into arabic numbers within the C++ Programming forums, part of the General Programming Boards category; I'm trying to write a program that takes roman numbers and outputs regular arabic numbers. I'm having trouble with the ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    16

    Making roman numerals into arabic numbers

    I'm trying to write a program that takes roman numbers and outputs regular arabic numbers.
    I'm having trouble with the numbers such as 4 (IV), 9 (IX), 40 (XL),
    90 (XC) and so on.
    I tried the if statement:
    if(rome[i] == 'C' && rome[(i)+1] =='M')
    I'm attaching the code so you can see it all,
    Any suggestions?
    Attached Files Attached Files

  2. #2
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Well the way you have it, IX will be 19, not 9.When you check for the two number such as IX, increment i, so it goes to the next letter after X. Same with the other double values.

    So:
    Code:
    int i;
    for(i = 0; i < thing.length(); i++)
    {
    if(thing[i] = 'I' && thing[i + 1] == 'X')
    {
       a = 9;
        i++;
    }
    /* ... */
    You've got it down pretty well, keep trying. You should post the main code, it's not that big...
    Last edited by CheesyMoo; 04-13-2003 at 12:35 AM.
    If you ever need a hug, just ask.

  3. #3
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Also you don't need to include fstream and cmath...
    If you ever need a hug, just ask.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 09:45 PM
  2. Making some random numbers..
    By Ripper1 in forum C++ Programming
    Replies: 4
    Last Post: 08-06-2003, 05:42 AM
  3. Replies: 4
    Last Post: 03-03-2003, 03:52 PM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21