"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
let input = inputString[currentLine++];
return input === undefined ? undefined : JSON.parse(input);
}
/* Please do not modify anything above this line */
/* Write your code here */
/* Please do not modify anything below this line */
function main() {
const principal = readLine();
const time = readLine();
const apprPercentage = readLine();
const finalValue = calculateFinalValueWithAppreciation(principal, time, apprPercentage);
console.log(finalValue);
}
Final Value with Appreciation
Given principal amount
principal as an input, time period in years time and appreciation percentage apprPercentage as optional inputs, write a JS function to return the final value finalValue with the given appreciation percentage and time period. The default values for time and apprPercentage are 2 and 5 respectively.
Quick Tip
The formula to calculate the final value with appreciation is,
finalValue = principal * (1 + time * appreciation / 100)
Sample Input 1
1000
2
3
Sample Output 1
1060
Sample Input 2
3000
Sample Output 2
3300.0000000000005
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});
main();
});
function readLine() {
return inputString[currentLine++];
return input === undefined ? undefined : JSON.parse(input);
}
function calculateFinalValueWithAppreciation(principal, time, apprPercentage) {
let finalValue;
finalValue = principal * (1 + time * appreciation / 100);
return finalValue;
}
/**** Ignore above this line. ****/
function main() {
const principal = readLine();
const time = readLine();
const apprPercentage = readLine();
const finalValue = calculateFinalValueWithAppreciation(principal, time, apprPercentage);
console.log(finalValue);
}
Comments
Leave a comment