Bob a builder has come to you to build a program for his business. He needs to determine the square footage of a room in order to buy materials and calculate costs. Bob charges $125 per square metre. The program is going to ask the user to enter the name of a room. It will then ask for the width and length of the room (in meters) to be built. The program will calculate the room area and use this information to generate an approximate cost. Your program will display the room, the total area and the approximate cost to the screen.
"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() {
return inputString[currentLine++];
}
function main() {
const nameRoom = readLine();
const width = readLine();
const length = readLine();
console.log("Room name: " + nameRoom)
console.log("total area: " + length*width +" m^2")
console.log("approximate cost: " + "$" + length*width*125)
}
Comments
Leave a comment