Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that converts a positive integer less than 4000 into the Roman Number system in C++. Only use if statements. When I type

Write a program that converts a positive integer less than 4000 into the Roman Number system in C++. Only use if statements. When I type an integer in the 100s or below it gives me the right roman numbers, but when I type an integer in the 1000s it donsn't have the M.

If I enter 3562 it give me DLXII when it should be MMMDLXII

This is my input, please find what's wrong. Thank You.

#include using namespace std;

int main() { int num; cout << "Enter the whole number less than 4,000 you wish to convert: "; cin >> num; int a,b,c,d; a=b=c=d=0; if(num<4000) { a=num%10; b=num%100-a; c=num%1000-(a+b); d=num%1000-(a+b+c); } if(d>0) { int x; x=d/1000; for(int i=0; i0) { int x; x=c/100; switch (x) { case 1: cout << "C"; break; case 2: cout << "CC"; break; case 3: cout << "CCC"; break; case 4: cout << "CD"; break; case 5: cout << "D"; break; case 6: cout << "DC"; break; case 7: cout << "DCC"; break; case 8: cout << "DCCC"; break; case 9: cout << "CM"; break; } } if(b>0) { int x; x=b/10; switch (x) { case 1: cout << "X"; break; case 2: cout << "XX"; break; case 3: cout << "XXX"; break; case 4: cout << "XL"; break; case 5: cout << "L"; break; case 6: cout << "LX"; break; case 7: cout << "LXX"; break; case 8: cout << "LXXX"; break; case 9: cout << "XC"; break; } } if(a>0) { switch (a) { case 1: cout << "I" << endl; break; case 2: cout << "II" << endl; break; case 3: cout << "III" << endl; break; case 4: cout << "IV" << endl; break; case 5: cout << "V" << endl; break; case 6: cout << "VI" << endl; break; case 7: cout << "VII" << endl; break; case 8: cout << "VIII" << endl; break; case 9: cout << "IX" << endl; break; } } return 0; }

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

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions