Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

2. Define identity.

Answered: 1 week ago

Question

Developing and delivering learning that is integrated with the job.

Answered: 1 week ago