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

Arabic to Roman Numerals!!! C++ Programming Help Please! Program Info: Write a p

ID: 3882581 • Letter: A

Question

Arabic to Roman Numerals!!! C++ Programming Help Please!

Program Info: Write a program that accepts a year written as a four-digit Arabic (ordinary) numeral and outputs the year written in Roman numerals. Important Roman numerals are V for 5, X for 10, L for 50, C for 100, D for 500, and M for 1,000. Recall that some numbers are formed by using a kind of subtraction of one Roman “digit”; for example, IV is 4 produced as V minus I, XL is 40, CM is 900, and so on. A few sample years: MCM is 1900, MCML is 1950, MCMLX is 1960, MCMXL is 1940, MCMLXXXIX is 1989. Assume the year is between 1000 and 3000. Your program should include a loop that lets the user repeat this calculation until the user says she or he is done.

More Important Info:

Enter an Arabic number: 2456

2456 is MMCDLVI in Roman numerals

Play again? Y

Enter an Arabic number: 1359

1359 is MCCCLIX in Roman numerals

Play again? N

Read the number as an integer: e.g. 9786

Use arithmetics to separate each digit into separate ints: (do you know what the modulus operator is? “%” No? look it up.)

ones will be 6

tens will be 8

hundreds will be 7

thousands will be 9

***use FOUR SWITCH CASES to output the correct string for each digit:

1. cout<<”XX” in case of tens being 2

2. cout<<”XXX” in case of tens being 3

3. etc.

***As with all the projects in this chapter, wrap this whole thing in a “Play another game” loop to allow the user to play as many times as they like.

REMEMBER use 4 SWITCH CASES FOR OUTPUT! (In other words use SWITCH STATEMENTS for displaying the output).

THANK YOU! :)

Explanation / Answer

//please see the code below:

#include<iostream>
using namespace std;
int main()
{   int n;
    char answer = 'Y';

  
     if(answer == 'Y' && answer != 'N')
     {Scary:

     cout << " Enter an Arabic number: ";
     while(cin>>n)
     {
      cout<<endl<<n<<" is ";
     int i,j,k,l;
     l=(n/1000)*1000;
     if(l==1000)
          cout<<"M";
     if(l==2000)
          cout<<"MM";
     if(l==3000)
          cout<<"MMM";
     if(l==4000)
          cout<<"-IV";
     if(l==5000)
          cout<<"-V";
     if(l==6000)
          cout<<"-VI";
     if(l==7000)
          cout<<"-VII";
     if(l==8000)
          cout<<"-VIII";
     if(l==9000)
          cout<<"-IX";
     if(l==10000)
          cout<<"-X";
     k=(n%1000);
     k=(k/100)*100;
     if (k == 100)
       cout<<"C";
   else if (k == 200)
       cout<<"CC";
   else if (k == 300)
       cout<<"CCC";
   else if (k == 400)
       cout<<"CD";
   else if (k ==500)
       cout<<"D";
   else if (k == 600)
       cout<<"DC";
   else if (k == 700)
       cout<<"DCC";
   else if (k ==800)
       cout<<"DCCC";
   else if (k == 900)
       cout<<"CM";
     k=n%1000;
     l=k%100;
     j=(l/10)*10;
     if (j == 10)
       cout<<"X";
   else if (j == 20)
       cout<<"XX";
   else if (j == 30)
       cout<<"XXX";
   else if (j == 40)
       cout<<"XL";
   else if (j ==50)
       cout<<"L";
   else if (j == 60)
       cout<<"LX";
   else if (j == 70)
       cout<<"LXX";
   else if (j ==80)
       cout<<"LXXX";
   else if (j == 90)
       cout<<"XC";
     i=l%10;
     if (i == 1)
       cout<<"I";
   else if (i == 2)
       cout<<"II";
   else if (i == 3)
       cout<<"III";
   else if (i == 4)
       cout<<"IV";
   else if (i ==5)
       cout<<"V";
   else if (i == 6)
       cout<<"VI";
   else if (i == 7)
       cout<<"VII";
   else if (i ==8)
       cout<<"VIII";
   else if (i == 9)
       cout<<"IX";
   cout<<" in Roman numerals"<<endl;

    cout <<" Play again?(Y/N): ";
    cin >> answer;
    answer = toupper(answer);

    if(answer == 'Y' && answer != 'N'){goto Scary;}
    else if(answer == 'N' && answer != 'Y'){return 0;}
     }

     }
     return 0;
}

OUTPUT


Enter an Arabic number: 2456

2456 is MMCDLVI in Roman numerals

Play again?(Y/N): Y

Enter an Arabic number: 1359

1359 is MCCCLIX in Roman numerals

Play again?(Y/N):

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