Problem 16. chocolatebills.js

 /*Question

Chocolate bill
Bablu went to a shop to buy some chocolates and ice creams.
Help him to calculate the bill.

Input
4 lines containing one integer each

First line denotes the cost of 1 chocolate.

Second line denotes the number of chocolate bought by Bablu.

Third line denotes the cost of 1 ice cream.

Fourth line denotes the number of ice creams bought by Bablu.

Output
One line containing one integer, denoting the total money to be paid by Bablu.

Example
Input:

5
3
15
2
Output:

45
Explanation:

First line contains 5, which means the cost of one chocolate is 5 rupees.
Second line contains 3, which means Bablu bought 3 chocolates.
Third line contains 15, which means the cost of one ice cream is 15 rupees.
Fourth line contains 2, which means Bablu bought 2 ice creams.
So, the total bill is 45 rupees.
*/

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 c1 = parseInt(readLine()); // cost of 1 chocolate 5

let n1 = parseInt(readLine()); //no. of chocolates 3

let c2 = parseInt(readLine()); // cost of 1 icecream 15

let n2 = parseInt(readLine()); //no. of icecream 2

console.log((c1 * n1) + (c2 * n2)); // 5*3 + 15*2 = 45

Terminal:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node chocolatebills.js <input.txt 45 Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$

Comments

Popular posts from this blog

Problem 33. patter122333.js

Problem 38. diamond.js