Computer Science, asked by saheliLakra, 6 months ago

Accept two numbers and a mathematical operator write a program using switch case To display the result depending on operator . Assume that both are non zero number?​

Answers

Answered by valeriy69
3

\small\mathsf\color{pink}{Solution\: using\: JavaScript\: on\: nodejs}

const readline = require("readline")

const rl = readline.createInterface({

input: process.stdin,

output: process.stdout

})

const q1 = () => {

return new Promise(resolve => {

rl.question("enter num: ", num => resolve(parseInt(num)))

})

}

const q2 = () => {

return new Promise(resolve => {

rl.question("enter num: ", num => resolve(parseInt(num)))

})

}

const q3 = () => {

return new Promise(resolve => {

rl.question("enter operator: ", op => resolve(op))

})

}

const main = async () => {

let n1 = await q1()

let n2 = await q2()

let op = await q3()

switch (op) {

case "*":

console.log(n1 * n2)

break

case "/":

console.log(n1 / n2)

break

case "+":

console.log(n1 + n2)

break

case "-":

console.log(n1 - n2)

break

default:

console("unsupported operator")

}

rl.close()

}

main()

Supports * / + - operators.

\small\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Answered by Anonymous
2

Answer:

const readline = require("readline")

const rl = readline.createInterface({

input: process.stdin,

output: process.stdout

})

const q1 = () => {

return new Promise(resolve => {

rl.question("enter num: ", num => resolve(parseInt(num)))

})

}

const q2 = () => {

return new Promise(resolve => {

rl.question("enter num: ", num => resolve(parseInt(num)))

})

}

const q3 = () => {

return new Promise(resolve => {

rl.question("enter operator: ", op => resolve(op))

})

}

const main = async () => {

let n1 = await q1()

let n2 = await q2()

let op = await q3()

switch (op) {

case "*":

console.log(n1 * n2)

break

case "/":

console.log(n1 / n2)

break

case "+":

console.log(n1 + n2)

break

case "-":

console.log(n1 - n2)

break

default:

console("unsupported operator")

}

rl.close()

}

main()

Supports * / + - operators.

Similar questions