Loging

Hello members,

I have a question is there a possibility to log the input and output from a Roman numeral conversion tool? So that all the conversions automatically printed on the screen? For example you look at http://hbs-ict.nl/rnc/
============================================================================
index.html
==============================================================================
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- Googlr fonts -->
<link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<title>Roman Numeral Conversion for IT -ECONOMICS with logging</title>
</head>
<body>
<div class="main">
<h1>Roman Numeral Converter for IT -ECONOMICS with logging</h1>
<!-- arbic input -->
<input id="arabicInput" type="text" name="arabic" placeholder="arabic numbers">
<!-- roman input -->
<input id="romanInput" type="text" name="roma" value="" placeholder="roman numbers">
</div>
<script type="text/javascript" src="app.js">
</script>
</body>
</html>

==========================================================================
APP.JS
==========================================================================

const arabicInput = document.getElementById("arabicInput");
const romanInput = document.getElementById("romanInput");

arabicInput.addEventListener("input",(e)=>{
romanInput.value = arabicToRoman(e.target.value);
});
romanInput.addEventListener("input",(e)=>{
arabicInput.value = romanToArabic(e.target.value);

});

function arabicToRoman(number){
let roman = "";
const romanNumList = {M:1000,CM:900, D:500,CD:400, C:100, XC:90,L:50, XV: 40, X:10, IX:9, V:5, IV:4, I:1};
let a;
if(number > 3999)
return "Enter a number between 1 and 3999";
else{
for(let key in romanNumList){
a = Math.floor(number / romanNumList[key]);
if(a >= 0){
for(let i = 0; i < a; i++){
roman += key;
}
}
number = number % romanNumList[key];
}
}

return roman;
}
function romanToArabic(romanNumber){
romanNumber = romanNumber.toUpperCase();
const romanNumList = ["CM","M","CD","D","XC","C","XL","L","IX","X","IV","V","I"];
const corresp = [900,1000,400,500,90,100,40,50,9,10,4,5,1];
let index = 0, num = 0;
for(let rn in romanNumList){
index = romanNumber.indexOf(romanNumList[rn]);
while(index != -1){
num += parseInt(corresp[rn]);
romanNumber = romanNumber.replace(romanNumList[rn],"-");
index = romanNumber.indexOf(romanNumList[rn]);
}
}
return num;
}

==========================================================================
CSS
===========================================================================
body{
margin: 0;
padding: 0;
box-sizing: border-box;
font-size: 10px;
font-family: 'Quicksand', sans-serif;
background-image: linear-gradient(315deg,#7EE8FA 0%,#80FF62 74%);
}
.main{
display: flex;
flex-direction: column;
align-items: center;
/*justify-content: center;*/
padding: 10px;
height: 96vh;
}
h1{
font-size: 3rem;
color: #fff;
font-weight: bold;
}
input{
outline: 0;
width: 60vw;
margin: 10px 0;
height: 80px;
padding: 5px;
padding-left: 20px;
border-style: none;
border-radius: 5px;
background: rgba(138,138,138,.4);
font-size: 3.5rem;
color:#fff;
text-align: center;
font-family: 'Quicksand', sans-serif;
}
::placeholder{
color: #fff;
}

@media(max-width: 500px) {
body{
padding-top: 20px;
}
h1{
font-size: 2rem;
}
input{
width: 90vw;
font-size: 2rem;
}

}
============================================================================
Last edited on
This appears to be Javascript. Is that intended?
where is the c++ code?

Where do you want it 'logged' ... you can pop up a console, but I don't think the web page users would see it, eg in the js? If its just something for yourself, that would be ok I guess? I can't click on your links...

in the c++ code part of your program add a cout statement would do it.
Last edited on
@jonnin yes its for my self if it is possible to save input input and output for example in a popup i'm happy.

@repeater if you have something else i wil be able to use in C++ let me see with the specs i ask with logging.

Thanks
would a console.log(whatever) in the .js file do it?

the reason we are asking about c++ .... look at the forum name. Take a guess what language we discuss here :P
Topic archived. No new replies allowed.