![]() |
|
#1
|
|||
|
|||
Frustrating C++ problem... Roman numeralsI've been trying to wrap my head around this one for the past few days... to start, I'm not all that good at programming, so I'm probably just forgetting minor things I'm supposed to know by now. But anyway.... I've been assigned a program that will take either arabic or roman numerals and spit roman numerals back out. That much I could do. However we're required to use a class that was designed for us, and I can't for the life of me figure out how to go about it. All we got to start was the class below (minus the result1-4 ints. Those were my doing)
1. complete the methods. 2. verify that the "conditions maintained in class" is correct. 3. write an interface to the class that will allow the user to enter arabic and Roman Numerals, and return roman numerals. 4. complete the documentation You may find it helpful to consider the use of strcpy and strcat in cstring. The help in initializing and building strings. The data type char* is a string represented as an array of character. */ CPP / C++ / C Code:
That's what I have so far... I'm sure it's a mess, but I got to a point where all I could do was get it to compile, even though it doesn't do anything. I don't know how to work with strings really (arrays I can play with a little), so how to convert the arabic number to roman numerals, or how to even get the roman numeral input option to do anything is freezing me up. If anyone could give me some idea how to fix this I'd be grateful. |
|
#2
|
||||
|
||||
|
I assume this was the class you were given:
CPP / C++ / C Code:
All they do is get your input returnRoman() is the method that computes the Roman numeral and passes it back to main() to be output. So start by rearranging your program to get the proper functionality. And sprinkle couts at key places to see how your conversion is progressing. Oh, and thank you for reading the Guidelines first! It really helps ![]() __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#3
|
|||
|
|||
|
Thanks. Most of my confusion stemmed from the fact that the professor left a lab while sick, so he wasn't able to explain it and the professor standing in had a hard time explaining it himself. Now that he's back he explained it a little better in class and I have a better idea of what I'm supposed to do. My main confusion at this point is the arrays and strings (I believe there's one of each). I understand the concepts of what they do, but how to declare them, convert them, copy them, etc. I understand the logic now, I just can't find the code that makes it work (the book's a little helpful, but doesn't have nearly enough examples for the way I learn). The logic itself I think I've finally picked up on at least.
|
|
#4
|
|||
|
|||
|
Ok, here's what I've got now that I have a little more direction. My strcats in return roman don't seem to be working, I only get the thousands place when I check it with cout. And as for how to convert roman numeral input to an integer I'm completely lost. Definitely better off than I was though.
CPP / C++ / C Code:
|
|
#5
|
||||
|
||||
|
So I take it
CPP / C++ / C Code:
Code:
Put couts inside the if's to see what values are being genereated, and to make sure you are actually going into the if's. You also might want to try using the modulus (%) operator instead of those equations. It will be simpler. __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#6
|
|||
|
|||
|
It may mean to do the cin within the method. But there's not supposed to be anything else in there if I understood him correctly in our lab. It's supposed to be the simplest method, and as the lab I believe will be expanded on later. I will make that change though.
As for the ifs, it only appears to be going into 2 of them. Before this point it was giving me gibberish because I hadn't set it as anything, so initializing it as zero fixed that. But that part of the program I THINK I can make work myself. If I don't get that particular way of doing it to work I can always get it to pull the numerals another way and add them to the string, but I have a few things to try. The only thing I need to know is if my use of strcat is correct so I know I'm at least adding the numerals correctly, even if other parts of the code are interfering with it happening. If it's something else I can probably find it, but strcat is new to me. That leaves me with setRoman. cin.getline seems to not be working (missing include on my part maybe? I've never used it before) so no input options come up when I attempt to enter a roman numeral. Should I get that working I assume I can read the array one item at a time and if I need to use if/elses to convert that to an integer value. Might be long, but it would get the job done I think... Would that work? |
|
#7
|
||||
|
||||
|
Quote:
Your syntax for strcat() is fine as long as your temp values are never 0. It looks like they cannot be so that's good. Summary: Yep, your strcat() is fine! Quote:
Quote:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#8
|
|||
|
|||
|
I'll likely post one more update early in the morning. Lab is due tomorrow afternoon, so hopefully I'll make some more progress and be able to clear up little bugs, but I think I'm at least on my way to some sort of functional product. I appreciate the help a lot. Being completely honest I've gotten this far into my school's Computer Science curriculum because of the weight of the tests vs the labs. I understand concepts perfectly fine, implementing them is more my weakness. I'm by no means a programmer, had never touched it before going to college. And it's the first thing we get thrown into (I suppose to weed out the undedicated) so it's definitely been an uphill battle. But at least I'm stubborn enough to work on it when it's not really my thing, so hopefully I'll pull through.
Again, I appreciate the help, hopefully I might even have a finished product to post tomorrow, heh. |
|
#9
|
|||
|
|||
|
Some slight changes. I got my returnRoman method working, which was about half the battle. I'm pretty sure I know what to do to get setRoman going, but I can't get the string of input from the user. cin.getline wouldn't work, and someone reccomended I use gets, but that seems to be giving me problems too. It's my last real problem at least, and that's something. And hey, I have output.
(I'll be removing the couts in the methods I've already finished soon enough.) CPP / C++ / C Code:
I'll be searching the board for the answer I suppose. Just thought I'd give a progress update. Oh, and does that method of converting the roman numeral to integer look sound once I get it going? |
|
#10
|
||||
|
||||
|
Quote:
CPP / C++ / C Code:
Quote:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Graphic problem in Unreal Tournament 2004 | zerox | Computer Software Forum - Games | 10 | 09-Oct-2005 13:31 |
| a significant problem after installing Xp | mohammad | Computer Software Forum - Windows | 10 | 09-Aug-2005 08:03 |
| String problem | vaha | C Programming Language | 3 | 24-May-2005 19:21 |
| Another FX 5600 problem (but with details that might shed light on this) | BobDaDuck | Computer Hardware Forum | 2 | 16-Apr-2004 08:53 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The