Roman Numerals

This is a discussion on Roman Numerals within the C Programming forums, part of the General Programming Boards category; Hello, I have an assignment to write a program in C to convert a numerical year into a Roman numeral. ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    2

    Roman Numerals

    Hello,
    I have an assignment to write a program in C to convert a numerical year into a Roman numeral. I have been messing with it for about a week and I'm stuck on where to start and how to go about doing it. If any one could help me get started or throw out a few idea os pseudocodes to get me on the right track I would appreciate it.
    Thanks.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Write out the decimal number in terms of place-value notation ie thousandths, hundreds, tens, and units digits.
    Now convert each of those constituent digits to its equivalent Roman numeral:

    Year 1995 == 1000 (M) + 900 (CM) + 90 (XC) + 5 (V) --> "MCMXCV"
    Year 1989 == 1000 (M) + 900 (CM) + 80 (LXXX) + 9 (IX) --> "MCMLXXXIX"

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    2

    Roman

    I started with this now I'm scratching my head wondering how to turn the 1's and 2' etc. into M,C,D,L,X,V, and I. I may have went at this the wrong way but I dont know. I figured I would error check the exceptions (ie IV, IX, XL, CM, etc.) later in for or do while loops. Any ideas on whether I ma going about this the right way, and maybee where to go with it so it makes sence, would greatly be appreciated.



    Code:
    #include <stdio.h>
    #include<stdlib.h>
    #include <time.h>
    
    void main()
    {
    	int year; 
    	int Roman;
    	int M;
    	int D;
    	int C;
    	int L;
    	int X;
    	int V;
    	int I;
    	int change[6];
    			
    			printf("Enter a year I'll convert it to its Roman Numeral Equivalent \n");
    			scanf("%d", &year);
    			
    			M = year / 1000;
    			change[0] = year%1000;
     			
    			D = change[0] / 500;
    			change[1]= change[0]%500;
    			
    			C = change[1] / 100;
    			change[2] = change[1]%100;
    			
    			L = change[2] / 50;
    			change[3] = change[2] % 50;
    			
    			X = change[3] / 10;
    			change[4] = change[3] % 10;
    			
    			V = change[4] / 5;
    			change[5] = change[4] % 5;
    			
    			I = change[5] / 1;
    			
    			
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 08-21-2006, 06:42 AM
  2. Using loops for check a roman number input.
    By eryell in forum C++ Programming
    Replies: 9
    Last Post: 04-12-2006, 11:04 AM
  3. converting arabic to roman numerals
    By kaisha8 in forum C++ Programming
    Replies: 2
    Last Post: 09-26-2004, 01:02 AM
  4. Making roman numerals into arabic numbers
    By Mule in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2003, 11:35 PM
  5. Need help with Roman Numerals
    By kiddprogrammer in forum C Programming
    Replies: 6
    Last Post: 04-01-2003, 10:45 PM

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