Need Some Programming Help
Need Some Programming Help
Hey guys,
So I'm taking an intro to programming class and for our third assignment, the professor is asking us to write a program which will take integers and convert them into roman numerals.
I am not exactly sure how to do this as my C skills are fairly limited but here's an idea of what I think is the process. My main difficulty right now is that I am not sure which commands or functions are needed to identify the integers, "break them apart" (i.e. separate 213 into 200 + 10 + 3), and convert them into the roman numerals.
Here's what I THINK is what I need to do:
1) Read an input from the user (so printf a message, then use scanf to take in the info)
2) Declare the variable types. So,
M = 1000;
D = 500;
C = 100;
L = 50;
X = 10;
V = 5;
I = 1;
3) Then somehow setup some kind of criteria where
If a number is less than say, 9, count the number of times it...???
That's where I can get stuck. I would think that I would need a list of tests so that the program tries to see if the user-supplied input passes the test of different categories.
Sorry, I'm really really newbie when it comes to this.
Any advice would be greatly appreciated.
Thanks!
So I'm taking an intro to programming class and for our third assignment, the professor is asking us to write a program which will take integers and convert them into roman numerals.
I am not exactly sure how to do this as my C skills are fairly limited but here's an idea of what I think is the process. My main difficulty right now is that I am not sure which commands or functions are needed to identify the integers, "break them apart" (i.e. separate 213 into 200 + 10 + 3), and convert them into the roman numerals.
Here's what I THINK is what I need to do:
1) Read an input from the user (so printf a message, then use scanf to take in the info)
2) Declare the variable types. So,
M = 1000;
D = 500;
C = 100;
L = 50;
X = 10;
V = 5;
I = 1;
3) Then somehow setup some kind of criteria where
If a number is less than say, 9, count the number of times it...???
That's where I can get stuck. I would think that I would need a list of tests so that the program tries to see if the user-supplied input passes the test of different categories.
Sorry, I'm really really newbie when it comes to this.
Any advice would be greatly appreciated.
Thanks!
Moderator
Regional Coordinator (Southeast)
Regional Coordinator (Southeast)




Joined: Dec 2003
Posts: 44,104
Likes: 4,421
From: Mooresville, NC
Probably not the best way to do it but could easily be done with a bunch if/else statements. Just check off it the value is larger than each of those groups. Starting with the largest one and then working you way down.
Each time its found to be larger then subtract that value from the entered value and have it restart checking from the top again. Each time a value is found take that letter and add it to string variable. For each additional value found just have the letter added to the end of the string value.
If this doesn't make sense I can try to write it out logically instead but my knowledge of actual remember correct terms is a little vague anymore and they would be from JAVA anyways.
Each time its found to be larger then subtract that value from the entered value and have it restart checking from the top again. Each time a value is found take that letter and add it to string variable. For each additional value found just have the letter added to the end of the string value.
If this doesn't make sense I can try to write it out logically instead but my knowledge of actual remember correct terms is a little vague anymore and they would be from JAVA anyways.
Moderator
Regional Coordinator (Southeast)
Regional Coordinator (Southeast)




Joined: Dec 2003
Posts: 44,104
Likes: 4,421
From: Mooresville, NC
Personally, I find it's easiest to break things apart if you make them into strings.
something along the lines of string x = 12345.tostring();
int y = x.length;
list <char> z = y.substring(y-1,y);
y--;
of course this is psuedocode, it won't actually work like this, but when I think about breaking things apart, I normally think of strings.
something along the lines of string x = 12345.tostring();
int y = x.length;
list <char> z = y.substring(y-1,y);
y--;
of course this is psuedocode, it won't actually work like this, but when I think about breaking things apart, I normally think of strings.
Trending Topics
Joined: May 2000
Posts: 27,921
Likes: 1,080
From: where the weather suits my clothes
Did you hear about this new search engine called Google that lets you find answers to questions just like that?
http://www.blackwasp.co.uk/NumberToRoman.aspx
http://javascript.about.com/library/blroman.htm
www.siafoo.net/snippet/120
http://www.blackwasp.co.uk/NumberToRoman.aspx
http://javascript.about.com/library/blroman.htm
www.siafoo.net/snippet/120

This should work in Java...don't know how this would turn out in C though.
123 mod 10 = 3
123 mod 100 = 23 / 10 = 2.3 ( math.floor makes this 2)
123 mod 1000 = 123 / 100 = 1.23 (math.floor makes this 1)
I hate programming with a passion
I've been out of the profession (software engineering) for over a year now, so I am in the early stages on gathering a touch of rust on my C coding skills, though I did use that language on a regular basis in a variety of applications for 22 years. Here's something a little interesting and yes, I am going to ramble a skosh.
Those of you in the business are no doubt familiar with a concept known as a binary search. Well, I wonder if any of you have ever had to actually write one in a work environment. COBOL has a built in binary search with the use of the reserved word, SEARCH (SEARCH ALL is a sequential search).
In my last job, I had to write a binary search in both Perl and C. The Perl script I wrote was used to verify the results of a data conversion where the required verification was to check to see if the files submitted for conversion were actually processed. The number of files to be checked was always 85,536, plus or minus a few (very few), and the log report to check against contained 1.1 million fully qualified converted files (full pathnames) against which the first list was checked. So that means reading through a list of 85,536 textual entries and trying to find each entry in another list of 1.1 million pathnames.
This was in 2002 and was run on Sun machines using, of course, UNIX. This pass took 2 1/2 seconds to check all 85,536 records in the 1.1 million record file. Pretty darned quick.
Those of you in the business are no doubt familiar with a concept known as a binary search. Well, I wonder if any of you have ever had to actually write one in a work environment. COBOL has a built in binary search with the use of the reserved word, SEARCH (SEARCH ALL is a sequential search).
In my last job, I had to write a binary search in both Perl and C. The Perl script I wrote was used to verify the results of a data conversion where the required verification was to check to see if the files submitted for conversion were actually processed. The number of files to be checked was always 85,536, plus or minus a few (very few), and the log report to check against contained 1.1 million fully qualified converted files (full pathnames) against which the first list was checked. So that means reading through a list of 85,536 textual entries and trying to find each entry in another list of 1.1 million pathnames.
This was in 2002 and was run on Sun machines using, of course, UNIX. This pass took 2 1/2 seconds to check all 85,536 records in the 1.1 million record file. Pretty darned quick.
Last edited by SouthernBoy; Oct 14, 2010 at 03:35 PM.
Thread
Thread Starter
Forum
Replies
Last Post
joflewbyu2
5G TLX (2015-2020)
139
Oct 8, 2015 11:16 AM
Yumcha
Automotive News
4
Sep 13, 2015 01:59 PM



