Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function roman_to_int(char c) which converts a Roman numeral (upper or l

ID: 3620467 • Letter: W

Question

   Write a function roman_to_int(char c) which converts a Roman
numeral (upper or lower case) to decimal, i.e.,
roman_to_int('I') ==> 1
roman_to_int('V') ==> 5
roman_to_int('X') ==> 10
roman_to_int('L') ==> 50
roman_to_int('C') ==> 100
roman_to_int('D') ==> 500
roman_to_int('M') ==> 1000
and similarly for the corresponding lower case letters. Write a main function
which repeatedly (until end-of-file) asks the user to enter a single Roman
numeral (letter) followed by the ENTER key and prints the value in decimal.
Name your program roman1.cpp.

Explanation / Answer

//here's a cheap but valid way to do it: int roman_to_int(char c) int value = 0; if (c == 'I' || c=='i') value = 1; else if (c == 'V' || c=='v') value = 5; ... else if (c == 'M' || c=='m') value = 1000; else value = -1; //This is only if the supplied character was invalid. return value; } // It is important that you use the single quote symbol (') when comparing characters. Please note that "||" means "or".
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote