Monday, April 5, 2021

Decimal To Roman Numeral in C++

 A simple program that will ask the user to give a number in decimal and convert it into Roman Numeral Equivalent using C++ programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com







Program Listing

// roman.cpp

// Prof. Jake R. Pomperada, MAED-IT,MIT

// www.jakerpomperada.com / www.jakerpomperada.blogspot.com

// jakerpomperada@gmail.com

// Bacolod City, Negros Occidental Philippines



#include <iostream>

#include <string>


using namespace std;


string decimal_to_roman(int x) {

    int dec[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};

    string num[13] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};

    string numeral;

    for(int i = 0; i < 13; i++) {

        while (x >= dec[i]) {

            x -= dec[i];

            numeral.append(num[i]);

        }

    }

    return numeral;

}

int main() {

    int decimal=0;

    

    cout <<"\n\n";

    cout <<"\tDecimal To Roman Numeral in C++";

    cout <<"\n\n";

    cout << "\tGive a Number : ";

    cin >> decimal;

    cout << "\n";

    cout << "\tThe given number is " << decimal;

    cout << "\n";

cout << "\tThe Roman Numeral Value is "<< decimal_to_roman(decimal);

cout << "\n\n";

    cout <<"\tEnd of Program";

    }



No comments:

Post a Comment