455,130 Members | 1,365 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,130 IT Pros & Developers. It's quick & easy.

# Integers to Roman Numerals Question

 P: 3 I've written the program and it works fine. but my instructor said that i can make the program short and use functions in it, but i cant really understand functions that good. so i just need a little help making the program short and use functions too. I'm posting my code here but i'm not posting the cin statements and the validating user entry loops. i'm just posting the if statements that i used. so here is my code: thousands = number / 100; // number is the user input. hundreds = number / 100 % 10; tens = number / 10 % 10; ones = number % 10; (thousands == 1 ? roman += "M": thousands == 2 ? roman += "MM": thousands == 3 ? roman += "MMM": hundreds == 1 ? roman += "C": hundreds == 2 ? roman += "CC": hundreds == 3 ? roman += "CCC": hundreds == 4 ? roman += "CD": hundreds == 5 ? roman += "D": hundreds == 6 ? roman += "DC": hundreds == 7 ? roman += "DCC": hundreds == 8 ? roman += "DCCC": hundreds == 9 ? roman += "CM" : roman = roman); (tens == 1 ? roman += "X": tens == 2 ? roman += "XX": tens == 3 ? roman += "XXX": tens == 4 ? roman += "XL": tens == 5 ? roman += "L": tens == 6 ? roman += "LX": tens == 7 ? roman += "LXX": tens == 8 ? roman += "LXXX": tens == 9 ? roman += "XC" : roman = roman); (ones == 1 ? roman += "I": ones == 2 ? roman += "II": ones == 3 ? roman += "III": ones == 4 ? roman += "IV": ones == 5 ? roman += "V": ones == 6 ? roman += "VI": ones == 7 ? roman += "VII": ones == 8 ? roman += "VIII": ones == 9 ? roman += "IX" : roman = roman); Mar 22 '07 #1