Problem 1. gstproblem1.js
/* Given the unit Price and GST percentage, compute the final price.
Input:
Two lines containing one integer each.
First line denotes the unit price.
Second line denotes the GST percentage.
Output:
One line containing the final price.
Example test case:
input
100
18
output
118
Algorithm:
1. Read the unit price
2. Read the GST percentage
3. Unit price + Gst*Unitprice (100+(100*18)/100)
4. Display the final price
*/
let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split('\n');
function readLine() {
idx++;
return data[idx - 1].trim();
}
//.......................................................................................
let unitPrice = parseInt(readLine()); // '100' string after parseInt will be converted to 100 integer
let gstValue = parseInt(readLine()); // '18' string after parseInt will be converted to 18 integer
let finalPrice = unitPrice + (gstValue * unitPrice) / 100; // 100 + (18*100)/100
console.log(finalPrice); // 118
Terminal:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node gstproblem1.js <input.txt
118
Comments
Post a Comment