Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Convert numeric value to roman numeral?
Old
veghead05
Guest
 
Status:
Posts: n/a
Default Convert numeric value to roman numeral? - 05-04-2009, 01:15 PM

How do I convert a number into a roman numeral?
I have an assignment to ask the user to enter a number, then display that number as a roman numeral.

Where are the roman numerals?
   
Reply With Quote
Old
HisWorld
Guest
 
Status:
Posts: n/a
Default 05-04-2009, 10:59 PM

haha, its not as straight forward as you seem to think. you know the conversion right? 3 = III, 5 = V, 10 = X.

Well just off the top of my head you will need to read the user input and set whatever they input to a numeric veriable. then have a series of conditional statements "if-then, else" For each possible number you need to dispaly what you know is the equivalent roman numerial. ex. user inputs a five, you set that equal to a variable named "world.numbers" have maybe ten if statements that run,
"if world.numbers == 1
output I
else
...................

if world.number == 5
output 5


I would suggest you have the user only be allowed to input number's between 1 and some number like 10.

This can be down by using a while loop, "while both 0 < world.numbers <= 10"


Tell me if this helps
   
Reply With Quote
Old
EricSkogen
Guest
 
Status:
Posts: n/a
Default 05-05-2009, 01:01 AM

As far as I know, there are no "Roman Numeral" objects. You would have to use the Latin characters. output them just like you would any other text.

As far as the conversion goes, you could try the 1=I 2=II approach, but if you need to accept a large set (>20) perhaps this would be more time efficient.
   
Reply With Quote
Old
Scott300
Senior Member
 
Status: Offline
Posts: 80
Join Date: Feb 2009
Location: Ohio
Default 05-05-2009, 11:10 PM

var number = 6 //test number
var times into 100 = 0 //if its 0 that means it cannot go into it do same for 50,5
var remainder after 100 = 0 // the remaining amount after its been divided do same for 50,5
bool 100 perfect = false // this tells us later if there is no remainder on the 100 do the same for 50,5
string finishednumber == "" // its blank for now, this is where we will write our finished digits to
if number can be divided by 100 in any way
{
times into 100 = number/100
remainder after 100 = remainder
if remainder after 100 == 0
{
100 perfect == true
}
}
//repeat for 50,5

if times into 100 > 0
{
loop times=times into 100
{
finishednumber = X.finishednumber
}
}
and so on you need to make sure you put the remainders in there also I am getting tired of writing this its a pain in the ass tbh if you really need this finished send me a pm ill help you with it =)
  Send a message via AIM to Scott300 Send a message via MSN to Scott300  
Reply With Quote
Hmm..
Old
veghead05
Guest
 
Status:
Posts: n/a
Default Hmm.. - 05-12-2009, 04:44 PM

I'm actually really confused by ur post scott, could you explain what you are doing there? The comments helped a little but I'm still lost.
   
Reply With Quote
Old
Scott300
Senior Member
 
Status: Offline
Posts: 80
Join Date: Feb 2009
Location: Ohio
Default 05-12-2009, 07:18 PM

Quote:
Originally Posted by veghead05 View Post
I'm actually really confused by ur post scott, could you explain what you are doing there? The comments helped a little but I'm still lost.
Tonight ill try and work it out in Alice instead of my head and post my findings.
  Send a message via AIM to Scott300 Send a message via MSN to Scott300  
Reply With Quote
Old
Scott300
Senior Member
 
Status: Offline
Posts: 80
Join Date: Feb 2009
Location: Ohio
Default 05-13-2009, 11:59 AM

OK, this works about 90% try like 122 for an example number. It has trouble converting any number that has 50 in it (ex- 151). But other than that it works great!
Attached Files
File Type: a2w roman.a2w (225.9 KB, 131 views)
  Send a message via AIM to Scott300 Send a message via MSN to Scott300  
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.