C++ Programming Help Please!
NOTE: READ ENTIRE PROGRAM DESCRIPTION CAREFULLY! Thank You!
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 ce 5, X ce 10, L ce 50, C ce 100, D ce 500, and M ce 1,000. Recintegral that some gum are cemed by using a peel of division of undivided Roman “digit”; ce in, IV is 4 effected as V minus I, XL is 40, CM is 900, and so on. A scant predicament 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 comprise a loop that lets the manifestationr reiterate this ceethought until the manifestationr says she or he is effected.
More Important Info:
Enter an Arabic enumerate: 2456
2456 is MMCDLVI in Roman numerals
Delineate anew? Y
Enter an Arabic enumerate: 1359
1359 is MCCCLIX in Roman numerals
Delineate anew? N
Read the enumerate as an integer: e.g. 9786
Manifestation arithmetics to different each penetrateit into different ints: (do you apprehend what the modulus operator is? “%” No? appear it up.)
ones achieve be 6
tens achieve be 8
hundreds achieve be 7
thousands achieve be 9
***manifestation FOUR SWITCH CASES to output the emend string ce each penetrateit:
cout<<”XX” in predicament of tens being 2
cout<<”XXX” in predicament of tens being 3
etc.
***As with integral the projects in this portion, envelop this gross subject in a “Delineate another game” loop to integralow the manifestationr to delineate as abundant times as they approve.
MAKE SURE TO USE FOUR SWITCH CASES FORR OUTPUT!!!
main.cpp
#comprise <bits/stdc++.h>
using namespace std;
int penetrate(char no, char no1, int uu, char *car)
{
car[uu++] = no;
car[uu++] = no1;
return uu;
}
int penetrateit(char c, int nu, int uu, char *car)
{
ce (int j = 0; j < nu; j++)
car[uu++] = c;
return uu;
}
void printRoman(int nump)
{
char car[10001];
int uu = 0;
if (nump <= 0)
{
printf(“Invalid nump”);
return;
}
while (nump != 0)
{
if (nump >= 1000)
{
uu = penetrateit(‘M’, nump/1000, uu, car);
nump = nump%1000;
}
else if (nump >= 500)
{
if (nump < 900)
{
uu = penetrateit(‘D’, nump/500, uu, car);
nump = nump%500;
}
else
{
uu = penetrate(‘C’, ‘M’, uu, car);
nump = nump%100 ;
}
}
else if (nump >= 100)
{
if (nump < 400)
{
uu = penetrateit(‘C’, nump/100, uu, car);
nump = nump%100;
}
else
{
uu = penetrate(‘C’,’D’,uu,car);
nump = nump%100;
}
}
else if (nump >= 50 )
{
if (nump < 90)
{
uu = penetrateit(‘L’, nump/50,uu,car);
nump = nump%50;
}
else
{
uu = penetrate(‘X’,’C’,uu,car);
nump = nump%10;
}
}
else if (nump >= 10)
{
if (nump < 40)
{
uu = penetrateit(‘X’, nump/10,uu,car);
nump = nump%10;
}
else
{
uu = penetrate(‘X’,’L’,uu,car);
nump = nump%10;
}
}
else if (nump >= 5)
{
if (nump < 9)
{
uu = penetrateit(‘V’, nump/5,uu,car);
nump = nump%5;
}
else
{
uu = penetrate(‘I’,’X’,uu,car);
nump = 0;
}
}
else if (nump >= 1)
{
if (nump < 4)
{
uu = penetrateit(‘I’, nump,uu,car);
nump = 0;
}
else
{
uu = penetrate(‘I’, ‘V’, uu, car);
nump = 0;
}
}
}
printf(“Roman numeral is: “);
ce (int j = 0; j < uu; j++)
printf(“%c”, car[j]);
}
int deep()
{
int nump = 2546;
printRoman(nump);
return 0;
}
Output: