C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

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 March 30th, 2005, 02:22 AM
ken_pasaway ken_pasaway is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 2 ken_pasaway User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 59 sec
Reputation Power: 0
Wink converts roman numerals to hindu arabic

could you please post a sample of program that converts roman numerals to hindu arabic?
Example:

XC converts to 90
1998 converts to MCMXCVIII

hope you'll grant my request............




-ken

Reply With Quote
  #2  
Old March 30th, 2005, 08:46 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
#dfddfg#


please ignore my post.

Reply With Quote
  #3  
Old March 30th, 2005, 09:06 AM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Hey Ken!
You can't ask for the programm...that's unethical! You can ask for an idea, which is what I'll give you...the coding will be up to you!

First: make a table with each roman symbol and its value: M 1000, C 100, L 50, etc.

Algo:
Code:
 
1) Get next two numbers (if at the begining...the first two letters!)
2) If first bigger than seccond (no substraction)
2.1) add value of number 1 to variable
2.2) get the current second number and the next
2.3) Go to (2)
3) If second bigger than first (substraction)
3.1) Substract first from second
3.2) Add result to variable (always the same variable)
3.3) Go to (1)
 
 
Example:
 
MCMXCVIII --> 1998
 
1) ---> M and C
2) ---> yes!
2.1) var = var + 1000
2.2) C and M
 
Next:
 
2) ---> NO
3) ---> YES
3.1) 900
3.2) var = var + 900 (now contains 1900)
 
Next:
 
1) X and C
 
.........
.........
.........
 


It's important to remember than the algo must stop if you get an end of string when you attempt to retrive a number (Letter)!

Hope this works for you!!

Good LUck!

ANibal.

Reply With Quote
  #4  
Old April 2nd, 2005, 07:34 AM
ken_pasaway ken_pasaway is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 2 ken_pasaway User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 59 sec
Reputation Power: 0
Wink conversion of roman to hindu...(extension)

by d way tnx 4 answering my question about the conversion of roman to hindu....ive made it alredy(conversion of hindu to roman) by using if-else function....d problem is dat i cant do the same thing in converting the roman numeral to hindu arabic....heres d program: (871-900) is d range.

#include <stdio.h>
void main()
{
int choose=0;
int hindu=0;
int roman=0;
char y='\0';
char n='\0';
printf("This program converts Hindu Arabic to Roman Numeral and vice versa.\n\n");
printf("1.Hindu Arabic to Roman Numeral\n");
printf("2.Roman Numeral to Hindu Arabic\n\n");
printf("choose:");
scanf("%d",&choose);
if (choose == 1) {
printf("Enter the Hindu[871-900]: ");
scanf("%d",&hindu);
if (hindu == 871){
printf("DCCCLXXI\n");
}
if (hindu == 872){
printf("DCCCLXXII\n");
}
if (hindu == 873){
printf("DCCCLXXIII\n");

}

else{
printf("Do you want to continue?\n");
printf("Y or N?\n");
scanf("%d%d",&y, n);
printf("choose: ");
scanf("%d",&choose);
}

}else if (choose == 2) {
printf("Enter the Roman[DCCCLXXI-CM]: ");
scanf("%d",&roman);
if (roman == DCCCLXXI){
printf("871\n");
}
}else {
printf("Do you want to continue?\n");
printf("Y or N?\n");
scanf("%d%d",&y, n);
printf("choose: ");
scanf("%d",&choose);
}
}


i marked red those words which makes my program go wrong,dats y i can't convert the roman to hindu i dnt know y it is not working....ill w8 4 ur reply!!tnx....

Reply With Quote
  #5  
Old April 3rd, 2005, 12:00 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Hey Ken!
You can't do scanf("%dn",&roman) and enter a secuence of chars!!!

scanf("%d",&roman);
if (roman == DCCCLXXI){
printf("871\n");

you must get chars and process them acrodingly!!

Good Luck!!

ANibal

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > converts roman numerals to hindu arabic


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

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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





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