This is for the arabic to to roman part, its not doing the thousands properly. its correctly finding the amount of 100s and 10s and 1's but its only working up to 3000 not 4000 not sure where ive gone round.
Code:
char *a2roman (int value, char *c1, char *c2, char *c3);
int main (void)
{
int arabicNum = 1;
int result;
char roman[15] = "";
do
{
printf ("Enter a integer in 1 to 4999 range of integers: \n\t");
scanf ("%d", &arabicNum);
}
while ((arabicNum < 1) || (arabicNum > 4999));
if ((arabicNum <= 4999) && (arabicNum >= 1000))
{
result = arabicNum / 1000;
strcat (roman, a2roman(result, "M", " ", " "));
arabicNum -= (result * 1000);
}
if ((arabicNum < 1000) && (arabicNum >= 100))
{
result = arabicNum / 100;
strcat (roman, a2roman(result, "C", "D", "M"));
arabicNum -= (result * 100);
}
if ((arabicNum < 100) && (arabicNum >= 10))
{
result = arabicNum / 10;
strcat (roman, a2roman(result, "X", "L", "C"));
arabicNum -= (result * 10);
}
if ((arabicNum < 10) && (arabicNum >= 1))
{
strcat (roman, a2roman(arabicNum, "I", "V", "X"));
}
printf ("The Roman numeral is: \n\t%s\n\n", roman);
printf ("\t\t ...Press any key to exit.");
getch();
return 0;
}
char *a2roman (int value, char *c1, char *c2, char *c3)
{
int i;
char rRoman[15] = "";
if ((value >= 1) && (value <= 3))
{
for (i = 0; i < value; i++)
strcat (rRoman, c1);
}
if ((value >= 5) && (value <= 8))
{
strcat (rRoman, c2);
for (i = 0; i < (value - 5); i++)
strcat (rRoman, c1);
}
if (value == 4)
{
strcat (rRoman, c1);
strcat (rRoman, c2);
}
/* If value = 9 */
if (value == 9)
{
strcat (rRoman, c1);
strcat (rRoman, c3);
}
return (rRoman);
}