mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-06-27 23:56:35 +08:00
added a UI and small changes
I added a UI and maked small changes.
This commit is contained in:
@@ -10,13 +10,13 @@ using namespace std;
|
|||||||
//This functions fills a string with character c, n times and returns it
|
//This functions fills a string with character c, n times and returns it
|
||||||
string fill( char c, int n )
|
string fill( char c, int n )
|
||||||
{
|
{
|
||||||
string s;
|
string s = "";
|
||||||
while( n-- ) s += c;
|
while( n-- ) s += c;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
//to convert to lowercase Roman Numeral
|
//to convert to lowercase Roman Numeral
|
||||||
|
// the function works recursively
|
||||||
string tolowerRoman( int n )
|
string tolowerRoman( int n )
|
||||||
{
|
{
|
||||||
if( n < 4 ) return fill( 'i', n );
|
if( n < 4 ) return fill( 'i', n );
|
||||||
@@ -36,7 +36,7 @@ string tolowerRoman( int n )
|
|||||||
}
|
}
|
||||||
|
|
||||||
//to convert to uppercase Roman Numeral
|
//to convert to uppercase Roman Numeral
|
||||||
|
// the function works recursively
|
||||||
string toupperRoman( int n )
|
string toupperRoman( int n )
|
||||||
{
|
{
|
||||||
if( n < 4 ) return fill( 'I', n );
|
if( n < 4 ) return fill( 'I', n );
|
||||||
@@ -61,6 +61,8 @@ int main()
|
|||||||
{
|
{
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
|
cout << "\t\tRoman numbers converter\n\n";
|
||||||
|
cout << "Type in decimal number between 0 up to 4000 (exclusive): ";
|
||||||
cin >> n;
|
cin >> n;
|
||||||
cout << n << " in Upper Roman Numerals is " << toupperRoman(n) << "\n";
|
cout << n << " in Upper Roman Numerals is " << toupperRoman(n) << "\n";
|
||||||
cout << n << " in Lower Roman Numerals is " << tolowerRoman(n) << "\n";
|
cout << n << " in Lower Roman Numerals is " << tolowerRoman(n) << "\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user