prob with pseudocode
|
|||
|
Rank: ? (1)
Member #: 28629 |
Hi, i'm doing pseudocode for now 1 month or so and working on a big problem for school, here's my problem
I need to "translate" numbers such as 6454 into Roman numeral I=1 V=5 X=10 L=50 C=100 D=500 M=1000 I worked to get all numbers seperatly like 6, 4, 5, 4 in some "if" but I don't know how to put Roman numeral instead of numbers. The answer will be MMMMMMCCCCLIIII for 6454 thx in advance for help |
||
|
|||
|
|||
|
Rank: ? (119)
Member #: 28292 |
You don't need to split a number in digits. Try this:
N = 6454; // This could be an other positiv integer A = N; B = A; IF A >= 1000; THAN BEGIN: A = [A / 1000]; // quotient B = B - A * 1000; // rest Write 'M' A times; A = B; END BEGIN IF A >= 500 THAN BEGIN: A = [A / 500]; B = B - A * 500; Write 'D' A times; A = B; END BEGIN IF A >= 100 THAN BEGIN: A = [A / 100]; B = B - A * 100; Write 'C' A times; A = B; END BEGIN IF A >= 50 THAN BEGIN: A = [A / 50]; B = B - A * 50; Write 'L' A times; A = B; END BEGIN IF A >= 10 THAN BEGIN: A = [A / 10]; B = B - A * 10; Write 'X' A times; A = B; END BEGIN IF A >= 5 THAN BEGIN: A = [A / 5]; B = B - A * 5; Write 'L' A times; A = B; END BEGIN IF A >= 1 THAN BEGIN: A = [A / 1]; B = B - A * 1; Write 'I' A times; A = B; END BEGIN » Post edited 2006-09-27, 08:17am by igorok.
|
||
|
Please login or register to post a reply.