May 16, 2008

I Need Help - it's about roman numbers in c/c++

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

free web hosting

I Need Help - it's about roman numbers in c/c++

wicked_soul
sad.gif 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.... rolleyes.gif

Reply

osknockout
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.

Reply

wicked_soul
QUOTE(osknockout @ Mar 27 2008, 05:40 AM) *
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....?

 

 

 


Reply

osknockout
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 was
C,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.

Reply

salamangkero
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 tongue.gif

CODE
#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 character
void repeat(char c) {
  int i;

  for (i=0; i<3; i++) {
    if(input[indx] == c) indx++;
  }
}

//advances the indx only once for this character
void check(char c) {
  if (input[indx] == c) indx++;
}


Reply

osknockout
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.

Reply

wicked_soul
salamangkero thanks a lot.... tongue.gif

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... tongue.gif xd.gif

Reply

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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : roman numbers

  1. Most Efficient Code To Get Prime Numbers - (7)
  2. C++ Roman Numeral Conversion Code Help - If-else Problem (5)
    thanks...
  3. How I Shall Scan Prime Numbers.. - that is 1,3,5,7,11,13,17,19... (4)
    I want to scan prime numbers ,have you logic to solve this problem? here is example of even
    numbers: CODE
    ----------------------------------------------------------------------------------------------------
    ---------- void main (void) {clrscr(); int a; printf("input any
    no."); scanf("%d"&a); if(a%2=0) {printf("the number is
    even"); getch(); }
    ----------------------------------------------------------------------------------------------------
    -------- Now I want to scan prime numbers...



Looking for roman, numbers, c, c,

Searching Video's for roman, numbers, c, c,
advertisement



I Need Help - it's about roman numbers in c/c++



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE