3
I need read 4 notes with weights of 2, 3, 4 and 1, respectively, for each of these notes and I must show this average accompanied by the message "Media: ". If this average is greater than or equal to 7.0, print the "Approved Student" message. If the calculated average is less than 5.0, print the "Failed Student" message. If the calculated average is between 5.0 and 6.9, inclusive, the program must print the message "Student in exam.".
In case the student is in exam, read a value corresponding to the exam grade obtained by the student. Then print the "Exam Note: " message accompanied by the typed note. Recalculate the average (add the exam score to the previously calculated average and divide by 2). and print the message "Approved student." (if the final average is 5.0 or more ) or "Student failed." (if the average has been 4.9 or less). For these two cases (approved or failed after taking the exam) present in the last line a message "Final media: " followed by the final average for this student.
Entradas: 2.0, 4.0, 7.5, 8.0
3.4 (Nota do Exame)
Saída:
Media: 5.4
Aluno em exame.
Nota do exame: 6.4
Aluno aprovado.
Media final: 5.9
That’s my code so far:
let data = input.split(' ')
let exame = input.split('\n')
let N1 = parseFloat(data.shift());
let N2 = parseFloat(data.shift());
let N3 = parseFloat(data.shift());
let N4 = parseFloat(data.shift());
let notaExame = parseFloat(exame.shift())
let media = ((N1*2)+(N2*3)+(N3*4)+(N4*1))/10;
let mediaFinal = (parseFloat(exame) + parseFloat(media))/2
console.log("Media: " + media.toFixed(1))
if (media >= 7.0){
console.log('Aluno aprovado.')
}else if (media.toFixed(1) >=5.0 && media.toFixed(1) <= 6.9){
console.log('Aluno em exame.')
console.log("Nota do exame: " + exame)
} else {
console.log('Aluno Reprovado')
}
if (mediaFinal <= 4.9){
console.log('Aluno reprovado.')
console.log('Media final: ' + mediaFinal.toFixed(1))
} else {
console.log('Aluno aprovado.')
console.log('Media final: ' + mediaFinal.toFixed(1))
}
My main problem is that when the result is higher than 5.0 or 7.0, where the student is automatically approved or flunked, the output is being that:
Media: 7.3
Aluno aprovado.
Aluno aprovado.
Media final: 5.3
Ideally, this is the way out:
Media: 7.3
Aluno aprovado.
From what I understand are not all students who take the exam but only those who were with average >= 5 and < 7. Only these students will take the exam and will have the calculation of the final average.
– anonimo
Just change where you are
let input = prompt("Entre com as notas")
putslet input = require("fs").readFileSync("stdin", "utf8");
.– Augusto Vasques
I have to reverse your edit because the Stack Overflow is not a Forum, see in What is the Stack Overflow we are a questions and answers site. Our format does not accept a change of focus in the question once it has already obtained answers, it invalidates the answers and the votes. If you have a new question or ask the author of the reply in the comments or open new question.
– Augusto Vasques