Question: 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

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!