Lab 1

Lab Description

In this lab we had to write a code that asks the user for a input number that would be converted to the roman numeral counterpart. The way the code was written was that we needed to know the roman numerals first and from there we used a while loop to check the input number to see if it could be converted into a roman numeral. If the number could be converted it would then check the many if statements to see which biggest roman numeral would work and then would subtract it from that value. It will then repeat the process until it reaches 0 and would display the roman numeral of the number inputted.

Code

program roman;
#include(“stdlib.hhf”)
static
n:int32;

begin roman;
repeat
stdout.put(“enter a number: “);
stdin.get(n);
mov(n,ebx);
while(ebx > 0) do
   if(ebx >= 500 ) then
     stdout.put(“D”);
     sub(500,ebx);
   elseif(ebx >= 400 ) then
     stdout.put(“CD”);
     sub(400,ebx);
   elseif(ebx >= 100 ) then
     stdout.put(“C”);
     sub(100,ebx);
   elseif(ebx >= 90 ) then
     stdout.put(“XC”);
     sub(90,ebx);
   elseif(ebx >= 50 ) then
     stdout.put(“L”);
     sub(50,ebx);
   elseif(ebx >= 40 ) then
     stdout.put(“XL”);
     sub(40,ebx);
   elseif(ebx >= 10 ) then
     stdout.put(“X”);
     sub(10,ebx);
   elseif(ebx >= 9 ) then
     stdout.put(“IX”);
     sub(9,ebx);
   elseif(ebx >= 5 ) then
     stdout.put(“V”);
     sub(5,ebx);
   elseif(ebx >= 4 ) then
     stdout.put(“IV”);
     sub(4,ebx);
   elseif(ebx >= 1 ) then
     stdout.put(“I”);
     sub(1,ebx);

     endif;

   endwhile;

stdout.put(nl);

until(n = 0);

end roman;

Screenshots

5 9 356

 

Leave a Reply

Your email address will not be published. Required fields are marked *