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

Can someone help me figure out how to write this code in C++ using the % modolus

ID: 3733674 • Letter: C

Question

Can someone help me figure out how to write this code in C++ using the % modolus operator and switch cases. Thank you! Can someone help me figure out how to write this code in C++ using the % modolus operator and switch cases. Thank you! 3. 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 numbers are V for 5, X for 10, L for 50, C for 100 D for 500 and M for 1000. 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, 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.

Explanation / Answer

#include <iostream>
using namespace std;
string roman(int year)
{
string ones[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
string tens[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
string hundreds[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
string thousands[] = {"", "M", "MM", "MMM"};

int thousands_index = year / 1000;
int hundreds_index = (year % 1000) / 100;
int tens_index = (year % 100) / 10;
int % 10;

string roman = thousands[thousands_index] + hundreds[hundreds_index] + tens[tens_index] + ones[ones_index];
return roman;
}
int main()
{
int year;
string flag;
while(1)
{
cout << "Enter the year between 1000 and 3000 : ";
cin >> year;
if(year >= 1000 && year <= 3000)
cout << "Roman equivalent is : " << roman(year) << endl;
else
cout << "Invalid year. Try again!!!" << endl;
cout << "Do you want to continue? 'done' to exit : ";
cin >> flag;
if(flag == "done")
break;
}

}

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