Trace the following flowchart for the input values 3, 12, -2, 5, 15, 1, 1, 1 and complete the trace table. Also, write pre-post-conditions for this flowchart. start sum1(0 sum2-0 i+1 i+i+1 num F i≤4 sum1 +sum1 + num i+1 F i≤4 i+i+1 sum1=sum2 num T "no" "yes" sum2sum2+ num end
Please help me is code correct for the flowchart below. I dont think it working right. Its suppposed to match the flowchart below. I'm also thinking that the output in not correct as well
Just correct the code:
function problem2() {
// this line will grab a string from the input box.
var inputString = document.getElementById("b").value;
// process the input string similar to flowchart2 function
const values = inputString.split(',').map(Number);
let result = values[0];
let isNegative = false;
for (let i = 1; i < values.length; i++) {
if (result < 0) {
isNegative = true;
result = -result;
}
if (isNegative) {
result -= values[i];
} else {
result += values[i];
}
}
if (isNegative) {
result = -result;
}
// write the result to the HTML page
document.getElementById("output2").innerHTML = result;
}
Step by step
Solved in 2 steps