Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Roman Numeral Calculator #855

Merged
merged 7 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Calculators/Roman-Numeral-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# <p align="center">Roman Numeral Calculator</p>

## Description :-

Calculator which takes the value in Roman numeral form and gives the results in decimal format.
This calculator only works within the specified range of standard Roman numeral form i.e. within the range 1 to 3999.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Screenshots :-

![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/3328c033-55ca-42a8-866e-60afbbc151cd)
22 changes: 22 additions & 0 deletions Calculators/Roman-Numeral-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css">
<title>Roman Numeral Calculator</title>
</head>

<body>
<div class="converter">
<h1>Roman Numeral Calculator</h1>
<label for="romanNumeral">Enter Roman Numeral following the standard rules of Roman numeral notation:</label>
<input type="text" id="romanNumeral" placeholder="e.g., XIV">
<button onclick="convertRomanToDecimal()">Convert</button>
<div id="result"></div>
</div>
<script src="./script.js"></script>
</body>

</html>
32 changes: 32 additions & 0 deletions Calculators/Roman-Numeral-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function convertRomanToDecimal() {
const roman = document.getElementById('romanNumeral').value.toUpperCase();
const romanToDecimalMap = {
'I': 1,
'V': 5,
'X': 10,
'L': 50,
'C': 100,
'D': 500,
'M': 1000
};

let decimal = 0;
let prevValue = 0;

for (let i = roman.length - 1; i >= 0; i--) {
const currentValue = romanToDecimalMap[roman[i]];
if (!currentValue) {
document.getElementById('result').innerText = "Invalid Roman Numeral";
return;
}

if (currentValue < prevValue) {
decimal -= currentValue;
} else {
decimal += currentValue;
}
prevValue = currentValue;
}

document.getElementById('result').innerText = `Decimal: ${decimal}`;
}
54 changes: 54 additions & 0 deletions Calculators/Roman-Numeral-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: linear-gradient(to right, #da6854,#ee3405);
}

.converter {
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
width: 300px;
}

h1 {
text-align: center;
}

label {
display: block;
margin: 10px 0 5px;
}

input {
width: 94%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 5px;
}

button {
width: 100%;
padding: 10px;
background-color: #c73d07;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}

button:hover {
background-color: #d4804f;
}

#result {
margin-top: 20px;
text-align: center;
font-size: 1.2em;
}

14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,20 @@ <h3>Converts Rectangular form into Polar form and vice versa.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Roman Numeral Calculator</h2>
<h3>Converts Roman Numeral form into Decimal form.</h3>
<div class="card-footer">
<a href="./Calculators/Roman-Numeral-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Roman-Numeral-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Salary To Hourly Calculator</h2>
Expand Down