[code]
void UserConvert(void)
{
int num1;
printf(“You have chosen to input the Arabic Number you wish to convert yourself. Please enter an Arabic Number: n”);
scanf(“%i”, &num1);
while (num1 >= 1000)
{
printf(“M”);
num1 -= 1000;
}
if (num1 >= 900)
{
printf(“CM”);
num1 -= 900;
}
if (num1 >= 500)
{
printf(“D”);
num1 -= 500;
}
if (num1 >= 400)
{
printf(“CD”);
num1 -= 400;
}
while (num1 >= 100)
{
printf(“C”);
num1 -= 100;
}
if (num1 >= 90)
{
printf(“XC”);
num1 -= 90;
}
if (num1 >= 50)
{
printf(“L”);
num1 -= 50;
}
if (num1 >= 40)
{
printf(“XL”);
num1 -= 40;
}
while (num1 >= 10)
{
printf(“X”);
num1 -= 10;
}
if (num1 >= 9)
{
printf(“IX”);
num1 -= 9;
}
if (num1 >= 5)
{
printf(“V”);
num1 -= 5;
}
if (num1 >= 4)
{
printf(“IV”);
num1 -= 4;
}
while (num1 >= 1)
{
printf(“I”);
num1 -= 1;
}
}
———
void main()
{
int userchoice;
do
{
printf(“Welcome to the numeral conversion program. Please press 1 to enter the Arabic Number you wish to convert, or 2 to convert a list of numbers: n”);
scanf(“%d”, &userchoice);
}
while ((userchoice != 1) && (userchoice != 2));
if (userchoice == 1)
UserConvert(); //function called here.
else if (userchoice == 2)
BatchConvert();
else;
}[/code]
Hi guys. I have to write a program in C to convert Arabic Numbers to Roman Numerals. This program compiles, but when i type in any number the result i get is MMDDCCLLXXVVI followed by a string of random characters. Does anyone have any idea why this could be?
ps. don’t worry about the BatchConvert function, one step at a time atm! 😛
Thanks in advance.
Would you care if this was written in Batch?
@echo off
ECHO Arabic Number?
SET /p Arabic1=
SET arabic=%arabic1%
:1000
IF %Arabic% GEQ 1000 (
SET M=%M%M
SET /a Arabic=Arabic-1000
) ELSE (
GOTO 900
)
GOTO 1000
:900
IF %Arabic% GEQ 900 (
SET CM=CM
SET /a Arabic=Arabic-900
)
IF %Arabic% GEQ 500 (
SET D=D
SET /a Arabic=Arabic-500
)
IF %Arabic% GEQ 400 (
SET CD1=CD1
SET /a Arabic=Arabic-400
)
:100
IF %arabic% GEQ 100 (
SET C=%C%C
SET /a arabic=arabic-100
) ELSE (
GOTO 90
)
GOTO 100
:90
IF %arabic% GEQ 90 (
SET XC=XC
SET /a arabic=arabic-90
)
IF %arabic% GEQ 50 (
SET L=L
SET /a arabic=arabic-50
)
IF %arabic% GEQ 40 (
SET XL=XL
SET /a arabic=arabic-40
)
:10
IF %arabic% GEQ 10 (
SET x=%X%X
SET /a arabic=arabic-10
) ELSE (
GOTO 9
)
GOTO 10
:9
IF %arabic% GEQ 9 (
SET IX=IX
SET /a Arabic=arabic-9
)
IF %arabic% GEQ 5 (
SET V=V
SET /a Arabic=arabic-5
)
IF %arabic% GEQ 4 (
SET IV=IV
Set /a arabic=arabic-4
)
:1
IF %arabic% GEQ 1 (
SET I=%I%I
SET /a arabic=arabic-1
) ELSE (
GOTO END
)
GOTO 1
:end
SET r=%M%%CM%%D%%cd1%%C%%XC%%L%%XL%%X%%IX%%V%%IV%%I%
ECHO %arabic1% Is %r%
PAUSE
I only Batch if possible, 2000 more lines of code, oh well.