| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
#dfddfg#
please ignore my post. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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.... |
|
#5
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > converts roman numerals to hindu arabic |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|