# Convert to Roman Numerals - Program not working, suggest a workaround!

• 08-20-2006
duffmckagan
Convert to Roman Numerals - Program not working, suggest a workaround!
Code:

```/* Write a general-purpose function to convert any given year into its roman equivalent. The following table shows the roman equivalents of decimal numbers: Decimal:.........Roman 1................i        5................v 10...............x 50...............l 100..............c 500..............d 1000.............m Example: Roman equivalent of 1988 is mdcccclxxxviii Roman equivalent of 1525 is mdxxv   */ #include<stdio.h> main() {         int year;         int convert (int year);                 while (1)         {                 printf("Note:Enter a four year digit year.\n\n");                 printf("Enter the year that you wanna convert to Roman: " );                 scanf ("%d", &year);                 if (year> 1999)                 {                         printf("Invalid Year.Please enter again.\n\n");                 }         }         convert(year); } convert(int year); {         int i;         {         i=(year/1000); //thousands place         if(i==1)         {         printf("m");         }         i=(year%1000)-(year/1000); //hundreds place         switch (i)         {         case 1:         printf("c");         break;                 case 2:         printf("cc");         break;                 case 3:         printf("ccc");         break;                 case 4:         printf("cd");         break;                 case 5:         printf("d");         break;                 case 6:         printf("dc");         break;                 case 7:         printf("dcc");         break;                 case 8:         printf("dccc");         break;                 case 9:         printf("dcccc");         break;                 }         i=(year-((year/100)*100))/10; //tens place         switch(i)         {         case 1:         printf("x");         break;         case 2:         printf("xx");         break;         case 3:         printf("xxx");     break;         case 4:         printf("xl");         break;         case 5:         printf("x");         break;         case 6:         printf("xl");         break;         case 7:         printf("xll");         break;         case 8:         printf("xlll");         break;         case 9:         printf("xllll");         break;         }     i=year%10; //ones place         switch(i);         {         case 1:         printf("i");     break;         case 2:         printf("ii");           break;         case 3:         printf("iii");         break;         case 4:         printf("iv");         break;         case 5:         printf("v");         break;         case 6:         printf("vi");         break;         case 7:         printf("vii");         break;         case 8:         printf("viii");         break;         case 9:         printf("ix");         break;         } } return 0; }```

The program looks too big, but its just cuz of the Case Statements.

So..can anybody suggest a workaround?

THe program doesn't work!
It gives some error related to the brackets of the 'convert' function! I can't debug it!

Any ideas fellas?
• 08-20-2006
Salem
> convert(int year);
Remove that ;

If you'd started with
Code:

```convert(int year); { }```
Then pressed compile, you would only have 3 lines to consider, and you'd probably figure it out.

> The program looks too big,
All those cases look just like array indices
Code:

```char *hundreds[] = { "c", "cc", "ccc", "cd" }; printf( "%s", hundreds[pos] );```
> printf("dcccc");
All your 9's are wrong, this should be "cm" for example.
• 08-20-2006
duffmckagan
Quote:

>printf("dcccc");
All your 9's are wrong, this should be "cm" for example.
[/quote]
Write a general-purpose function to convert any given year into its roman equivalent.
The following table shows the roman equivalents of decimal numbers:

Decimal:.........Roman
1................i
5................v
10...............x
50...............l
100..............c
500..............d
1000.............m

Example:
Roman equivalent of 1988 is mdcccclxxxviii
Roman equivalent of 1525 is mdxxv
[/quote]

Absolutely!
I was confused too! I just took a look at the example in the question and figured out that the 9 would be dcccc.
But logically it should have been cm!

Also, I have not yet reached the point of arrays. So it must be okay..to go ahead with this program which looks fine.

And the semicolon after the function --> convert (int year); ...was the most lousy mistake of all times!!! hehe
• 08-21-2006
sangken
you got that one right duffmckagan... :D maybe you copied the function prototype and forgot to remove the ;