In: Computer Science
Conversion of numeral to roman number:
Create a FLOWCHART and C++ PROGRAM that prompts the user to enter a number (from 1-3000 only) then output the number and its corresponding roman numeral number. ***validate the input (it must be 1-3000 only)
SAMPLE OUTPUT:
Enter a Number: 0
Number should be from 1-3000 only (Terminated)
Enter a Number: -5
Number should be from 1-3000 only (Terminated)
Enter a Number: 3500
Number should be from 1-3000 only (Terminated)
Enter a Number: 1994
Roman Number is: MCMXLIV
#include <bits/stdc++.h>
#include<String>
#include<iostream>
using namespace std;
// Function to convert decimal to Roman Numerals
string Roman(int num)
{
string roman="";
int numarr[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
string symbol[] =
{"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
int i=12;
while(num>0)
{
int div = num/numarr[i];
num = num%numarr[i];
while(div--)
{
roman+=symbol[i];
}
i--;
}
return roman;
}
int main()
{
int number = 3549;
string roman;
cout<<"\nENTER A NUMBER: ";
cin>>number;
if(number<1||number>3000)
{
cout<<"\nNumber should be
from 1-3000 only (Terminated)\n";
}
else
{
roman=Roman(number);
cout<<"Roman Number is:
"<<roman<<endl;
}
return 0;
}
Flowchart
main()
string Roman(int num)