|
|
|
![](clear.gif) |
Posted 2003-11-19, 01:20 PM
in reply to Hades-Knight's post "Need help"
|
![](clear.gif) |
![](clear.gif) |
![](clear.gif) |
*Double post for completion*
Done
Code:
--------------------------------------------------------------
#include<stdio.h>
int main(void)
{
int i, previous = 0, num, total = 0, flag = 0, key = 0, error = 0, number, repeat = 1;
char roman[50], roman2[50], pchar = 'z';
printf("Enter the Roman numeral: ");
scanf("%s",roman);
for (i = 0; i < 50; i++)
{
if (roman[i] == 'M')
num = 1000;
else if (roman[i] == 'D')
num = 500;
else if (roman[i] == 'C')
num = 100;
else if (roman[i] == 'L')
num = 50;
else if (roman[i] == 'X')
num = 10;
else if (roman[i] == 'V')
num = 5;
else if (roman[i] == 'I')
num = 1;
else if (roman[i] == '\0')
flag = 1;
else
error = 1;
if (num == previous)
repeat = repeat + 1;
else
repeat = 1;
if (repeat == 4 && num == 1)
{
error = 1;
flag = 1;
}
if (repeat == 2 && num == 5)
{
error = 1;
flag = 1;
}
if (repeat == 4 && num == 10)
{
error = 1;
flag = 1;
}
if (repeat == 2 && num == 50)
{
error = 1;
flag = 1;
}
if (repeat == 4 && num == 100)
{
error = 1;
flag = 1;
}
if (repeat == 2 && num == 500)
{
error = 1;
flag = 1;
}
if (flag == 0)
{
if (num == 0)
error = 1;
if (num > previous)
{
if (key == 1)
{
number = i;
i = 50;
}
total = (total - (2 * previous)) + num;
key = 1;
}
else
total += num;
previous = num;
num = 0;
}
else
{
number = i - 1;
i = 50;
}
}
if (roman[number + 1] != '\0')
error = 1;
if (error == 1)
printf("Error in input.\n");
else
printf("%d\n",total);
total = total * 2;
repeat = 1;
for (i = 0; i < 50; i++)
{
if (total >= 1)
roman2[i] = 'I';
if (total >= 5)
roman2[i] = 'V';
if (total >= 10)
roman2[i] = 'X';
if (total >= 50)
roman2[i] = 'L';
if (total >= 100)
roman2[i] = 'C';
if (total >= 500)
roman2[i] = 'D';
if (total >= 1000)
roman2[i] = 'M';
if (total == 0)
roman2[i] = '\0';
if (roman2[i] == pchar)
repeat = repeat + 1;
else
repeat = 1;
if (repeat == 4 && roman2[i] == 'I')
{
roman2[i - 2] = 'V';
roman2[i - 1] = '\0';
}
if (roman2[i] == 'M')
total -= 1000;
else if (roman2[i] == 'D')
total -= 500;
else if (roman2[i] == 'C')
total -= 100;
else if (roman2[i] == 'L')
total -= 50;
else if (roman2[i] == 'X')
total -= 10;
else if (roman2[i] == 'V')
total -= 5;
else if (roman2[i] == 'I')
total -= 1;
else if (roman2[i] == '\0')
i = 50;
pchar = roman2[i];
}
if (error != 1)
printf("%1s\n",roman2);
return(0);
}
![](images/synth/originalblue/misc/postbit/sigsep.gif)
D3V said:
This message is hidden because D3V is on your ignore list.
|
What is it they say about silence being golden?
Last edited by Medieval Bob; 2003-11-19 at 09:09 PM.
|
![](clear.gif) |
![](images/synth/originalblue/misc/postbit/cbgf.gif) |
![](clear.gif) |
|
|
|
|
|
|
|