.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 12th, 2005, 06:09 PM
comrade Cooney comrade Cooney is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Location: England
Posts: 3 comrade Cooney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 0
Send a message via AIM to comrade Cooney Send a message via MSN to comrade Cooney Send a message via Yahoo to comrade Cooney
Unhappy Roman Numerals convertor

howdy folks,

I've been set this assignment to make a calculator (just addition and subtraction thankfully :P) into which you can plug in Roman Numerals and get out a standard Arabic-form answer, along with the numerals tossed in.

The thing is, I'm still fairly new to .Net and have very little idea as to where to start.

I've made myself a module and put in some public constants, the basics, like so

Code:
Module  Module1

    Public Const I = 1
    Public Const V = 5
    Public Const X = 10
    Public Const  L = 50

End Module


But my confusion sets in when I get to numbers like 16 or 14; how do I get the calculator to recognise the general rule that "if the letter before is smaller, subtract it. If the letter before is larger, add it" which pretty much covers Roman Numerals. I'm not sure how to word this into .Net and all my books are sadly lacking.

Any help would be very much appreciated as I'm pretty much totally confused here ><

Reply With Quote
  #2  
Old October 12th, 2005, 06:25 PM
comrade Cooney comrade Cooney is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Location: England
Posts: 3 comrade Cooney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 0
Send a message via AIM to comrade Cooney Send a message via MSN to comrade Cooney Send a message via Yahoo to comrade Cooney
I'm assuming I'm going to have to do the actual calculations "behind the scenes" in the arabic form, so I'd also be really appreciative for any help on converting this arabic number back to roman numerals (In essence flipping the other code around)

again, any help would be greatly appreciated, this has just got me very frustrated ><

Reply With Quote
  #3  
Old October 13th, 2005, 05:09 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 996 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 11 m 36 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
There are two ways to do this.
Do the calculation in Roman, which is actually pretty easy.
You need two functions, expand() and collapse()
Expand() takes a roman numeral string, and unfolds it to only 'I's (roman 1), so XIV becomes "IIIIIIIIIIIIII".
Collapse takes a string of 'I's (roman 1) and rewrites it to a proper roman numeral.

All you have to do for the calculation then, is expand() both values, concatenate them, and collapse() the resulting string.

The alternative is converting the roman numerals to arabic first, doing the calculations, and then converting back.

Calculating arabic from roman can also be done in two ways, using the earlier expand() function, and reading the string length, or writing a specific function for it.

The same applies to the other way around.
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 278

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Roman Numerals convertor


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT