![]() |
|
#1
|
|||
|
|||
Frustration...Roman Numeral ProgramOk...I've been working on this program for quite sometime, and I have little idea what to do. I know I am supposed to use getline for inputting my data into the program because my program is supposed to read a set of test data like this:
I+XIX XXIII / V CCCL +MMI XIV- XXXV VI * IX So obviously, I have to set conditions and such so that it can read the roman numerals and extract the numerals and the operator. This code is probably a train wreck...but its what I have so far...can anyone help me out? I would greatly appreciate it... ~SpyD3R (Frustrated) CPP / C++ / C Code:
Last edited by JdS : 11-Nov-2005 at 18:33.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#2
|
|||
|
|||
More SpecificallyLet me be a tad bit more specific...
I really just need help with the getline() statments and setting the condtions...I have no idea where to start...Thanks SpyD3r ![]() |
|
#3
|
|||
|
|||
Re: More SpecificallyQuote:
I would also say that you should at least start with code that compiles. Quote:
I would recommend shrinking / commenting out code until the errors are gone then start from there. |
|
#4
|
|||
|
|||
Re: Frustration...Roman Numerial ProgramOk...I need to know where to start with getline(cin, bob) for example (bob would be the name of my string that I am inputting)
As posted above, the test data that I have has roman numerals that have operators directly next to them or spaced out dramatically. Such as: XIX+ VII or XXII+IV What I'm really asking is how do I separate and isolate each individual term in that line that I am pulling out of my test data. I know I should be using substrings, but how would they work? ~SpyD3R |
|
#5
|
|||
|
|||
Re: Frustration...Roman Numerial ProgramI'd start by reading the guidelines posted so that
1) We can read your code (Guideline 1) 2) We can understand your questions/difficulties (Guideline 2) Using #2, explain where the problem is (point to the specific code), what you want to do (be specific), and what it is you need help understanding. Quote:
Use getline() as you are. There are no conditions associated with getline() based on your needs so you need to explain the conditions you mean. __________________
Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with. |
|
#6
|
|||
|
|||
Re: Frustration...Roman Numerial Program[C++
getline(cin, bob); I know I need to extract substrings from my test data after my getline statement. Example of test data: VIV+ III <-- How would I go about separating that into substrings? (Note: There is no space in between the first roman numeral and operator). Another Example: XIX -X <--Same thing except the subtraction operator is right next to 10...how would I separate that? Finally, XXI+V <--All of the information together with no spaces...how is this separated using substrings? I just need an idea of how to separate things from one string into substrings, and then from those substrings, assign them to my variables which I am using (e1 (Roman numeral 1), oper(+, -, \, *), and e2(Roman numeral 2). Hoped that helped... ~SpyD3R Basically, I am trying to do this: read and display the original expression convert each Roman numeral to its Arabic equivalent compute the result display the expression with Arabic numbers display the result as an Arabic number Assumptions All data will be read from a data file via Linux redirection. All expressions in the data file will be valid (valid operators and Roman numerals). The Roman numerals and operator in each expression may be separated by 0 or more blanks. Each line in the data file will be terminated by a linefeed (endl). |
|
#7
|
|||
|
|||
Re: Frustration...Roman Numeral ProgramQuote:
This is a small example of how it could be done using those functions. CPP / C++ / C Code:
Last edited by JdS : 11-Nov-2005 at 18:31.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#8
|
||||
|
||||
Re: Frustration...Roman Numerial ProgramDon't use string, use char.
CPP / C++ / C Code:
Then: bob[0] is the first character (V in first example) bob[1] is the second character (I) bob[2] is the third character (V) etc. Or if you must use string look up the substr() method: bob.substr(0,1); is the first character (V) bob.substr(1,1) is the second character (I) bob.substr(2,1) is the third character (V) etc. And Sokar, with 53 posts under your belt, I know you've been told about the Guidelines and code tags. Reread Guideline #3. It'll help you post with the proper tags. __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#9
|
|||
|
|||
Re: Frustration...Roman Numerial ProgramQuote:
|
|
#10
|
||||
|
||||
Hello Sokar,Hi Sokar,
I think WaltP's post was not intended to discourage you. Just to give you information. Thats it. Quote:
GIDForums™ is now the only forum in the world offering custom [c] and [c++] and other syntax highlighting bbcode. So, it would be easier to look at the code and the syntax errors when we post the code between [c] and [/c] or [c++] and [/c++]tags. So, we can make use of it to the fullest extent possible and help the Original posters. Please dont stop posting. It makes a great difference to us. Your posts are always friendly and correct, that is very much appreciated. Thank You, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Frustrating C++ problem... Roman numerals | Elsydeon | C++ Forum | 10 | 01-Sep-2005 08:37 |
| Type casts ? | kai85 | C++ Forum | 12 | 23-Jun-2005 13:04 |
| [TUTORIAL] Calling an external program in C (Linux) | dsmith | C Programming Language | 4 | 22-Apr-2005 14:30 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 08:10 |
| Need help with a C program (Long) | McFury | C Programming Language | 3 | 29-Apr-2004 21:06 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The