Jump to content
xisto Community
Sign in to follow this  
wicked_soul

I Need Help its about roman numbers in c/c++

Recommended Posts

:P hy.... i really need help... we have to make a programm that checks if input string is roman number...and i'm beginner in c/c++so i don't really know how to do this.... so if anyone can help me,please.... THANK YOU.... :lol:

Share this post


Link to post
Share on other sites

Yo. That's kind of simple. Just check if the input only has characters from the set "I, V, X, L, C, D, M". If it doesn't, then it's not integer Roman numerals.
You can set up a while loop going through a character array with several if statements checking if the characters are any of the above.

If you're trying to find out what that number IS, you can see my previous post on this topic. See if it makes sense to you.

Reply back if need anything more.

Edited by osknockout (see edit history)

Share this post


Link to post
Share on other sites

Yo. That's kind of simple. Just check if the input only has characters from the set "I, V, X, L, C, D, M". If it doesn't, then it's not integer Roman numerals.You can set up a while loop going through a character array with several if statements checking if the characters are any of the above.

If you're trying to find out what that number IS, you can see my previous post on this topic. See if it makes sense to you.

Reply back if need anything more.


THANKS...but that's not enough...e.g. if i input XXXLCIM that isn't a roman number,but has characters from the set ''I,V,X,L,C,D,M''...so....?

Share this post


Link to post
Share on other sites

Alright. Then set up an character array with the stuff in series, e.g. num[0] = "I", num[1] = "V", etc.Consider the input as a string where each character is tested individually.Ok, let's see, some of the most complex statements in roman numerals:1999 - MCMXCIX (index-wise, 7-5-7-3-5-1-3)1444 - MCDXLIV (index-wise, 7-5-6-3-4-1-2)1949 - MCMXLIX (index-wise, 7-5-7-3-4-1-2)1494 - MCDXCIV (index-wise, 7-5-6-3-5-1-2)Say character n matches with index i in the array.Then character n+1 must have index less than or equal to i+2, say it has index j in the array.If j > i, then it is a standard roman numeral iff (if and only if) the preceding character wasC,X, or I - because these are the only prefix numerals, otherwise it is fine.Start from n=1 and repeat test all over the string with n++ or however you want to jump n by 1.

Share this post


Link to post
Share on other sites

Sorry, I really shouldn't do this (you should be doing your own homework) but I couldn't resist. It's been quite a while since I've undertaken exercises like this :lol:

#include <stdio.h>#include <string.h>int main();void repeat(char c);void check(char c);char input[] = "MMDCLXVII";int indx = 0;int main() {  repeat('M');  check('D');  repeat('C');  check('L');  repeat('X');  check('V');  repeat('I');  if (indx < strlen(input)) printf("Not a Roman Numeral\n");  else printf("Roman Numeral\n");}//advances the indx up to three times for this charactervoid repeat(char c) {  int i;  for (i=0; i<3; i++) {	if(input[indx] == c) indx++;  }}//advances the indx only once for this charactervoid check(char c) {  if (input[indx] == c) indx++;}

Share this post


Link to post
Share on other sites

salamangkero you evil person! Why -sweet god, why- would you do homework for n00bs?

 

And what's more evil... you didn't return(0).

This merits a FAIL.

...

Actually, it's kinda nice code.

That's a very clean style you have there.

Share this post


Link to post
Share on other sites

salamangkero thanks a lot.... :P and osknockout i don't know how to write this statements in programm ''Then character n+1 must have index less than or equal to i+2, say it has index j in the array. If j > i, then it is a standard roman numeral iff (if and only if) the preceding character was C,X, or I.'' ?? and i'm sorry for being such boring... :D:lol:

Share this post


Link to post
Share on other sites

Hey, no prob. I'm just trying to make you do your own homework. 'cause doing comp. sci. hmwk's good for ya. :lol: And sorry for the formalistic advice also. I've been through a series of calc. and physics tests, so everything lookslike theorem proving right now...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.