hey guys
I'm working on some homework for my C++ programming class and the program has to convert a number between 1 and 3999 into Roman numerals. I have to build a string but I'm not quite sure how to code it. I'm cool with figuring out all the computation and what not but I just need a couple hints I guess. I wrote down 57 and then "L" + "VII" in my notes but I totally forgot how to implement it. I'll be doing some browsing online and in my book but any help would be appreciated.
building strings
Started by restin84, Oct 30 2008 03:07 PM
5 replies to this topic
#1
Posted 30 October 2008 - 03:07 PM
|
|
|
#2
Posted 30 October 2008 - 03:21 PM
Well, you know you need to use the string library, right?
From there, you could probably just output the "L" and then the "VII" without a space between them to make a Roman Numeral.
If that isn't good, I haven't tried this myself, but I believe you can just "add" strings.
For example:
str1 = "L";
str2 = "VII";
str3 = str1+str2;
That should give you: str3 = LVII.
Edit: I just tested this, and the connecting strings with "+" does work.
From there, you could probably just output the "L" and then the "VII" without a space between them to make a Roman Numeral.
If that isn't good, I haven't tried this myself, but I believe you can just "add" strings.
For example:
str1 = "L";
str2 = "VII";
str3 = str1+str2;
That should give you: str3 = LVII.
Edit: I just tested this, and the connecting strings with "+" does work.
#3
Posted 30 October 2008 - 04:04 PM
cool thats defintately helpful. I got the skeleton of the program laid out nicely. I did include the string library as well. Haven't gotten to the string building thing yet but I'll let ya know how it works out
#4
Posted 30 October 2008 - 06:11 PM
You will also need to use modulo/integer division to capture individual digits.
myint/100 % 10 gives the 100's place
myint/10 % 10 gives the 10's place.
myint/100 % 10 gives the 100's place
myint/10 % 10 gives the 10's place.
#5
Posted 30 October 2008 - 09:03 PM
Wow winged, the way I've been doing that is so much more complicated.
For the hundreds I was doing things like ((int%1000)-10*(int%100) - (int%10))/100.
Thanks!
For the hundreds I was doing things like ((int%1000)-10*(int%100) - (int%10))/100.
Thanks!
#6
Posted 31 October 2008 - 04:42 AM
Someday I might dig up my old base conversion program that used logs to determine the number of digits.


Sign In
Create Account


Back to top









