Question: Design a program to convert a Roman numeral to a decimal number. The program should read a Roman numeral. You may read it as a

Design a program to convert a Roman numeral to a decimal number. The program should read a Roman numeral. You may read it as a string or one character at a time. Do the conversion and then output the decimal number.

Here are the letters you need to know:

Symbol = Value I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1,000

The Pseudocode i got was

Start

Prompt the user to enter a roman numeral

Save the input to romanNum

If romanNum is inputted as I

Then decimalNum is equal to 1

endif

If romanNum is inputted as V

Then decimalNum is equal 5

endif

If romanNum is inputted as X

Then decimalNum is equal to 10

endif

If romanNum is inputted as L

Then decimalNum is equal to 50

endif

If romanNum is inputted as C

Then decimalNum is equal to 100

endif

If romanNum is inputted as D

Then decimalNum is equal to 500

endif

If romanNum is inputted as M

Then decimalNum is equal to 1000

endif

Output decimalNum

Stop

Using that Pseudocode i typed

#include using namespace std;

int main () { int romanNum; int decimalNum; cout > romanNum; if(romanNum == 'I') { decimalNum = 1; }

if(romanNum == 'V') { decimalNum = 5; }

if(romanNum == 'X') { decimalNum = 10; }

if(romanNum == 'L') { decimalNum = 50; }

if(romanNum == 'C') { decimalNum = 100; }

if(romanNum == 'D') { decimalNum = 500; }

if(romanNum == 'M') { decimalNum = 1000; } cout

return 0; }

Whenever i type a Roman Numeral i get 0

Design a program to convert a Roman numeral to a decimal number.

I was wondering if my code is is bad or the Pseudocode i was given has an error somewhere.

DARomanNumeral Design4.exe Enter a roman numeral I Process exited after 2.061 seconds with return value Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!