Hi, I have been trying to solve the Gross Salary beginner problem. However, I am having trouble outputing the result. I am solving the problem in Nodejs. I have also tried using Math.round()and Number.toFixed(1) which gave the right answer for the given test case, but not for the whole problem.
Here is my code:
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
var lines = chunk.split('\n');
var numLines = lines[0];
var basicSalary = 0, grossSalary = 0, DA = 0, HRA = 0;
for(var i=0; i<numLines; i++){
basicSalary = parseInt(lines[i+1]);
if(basicSalary < 1500){
HRA = ((basicSalary*10)/100);
DA = ((basicSalary*90)/100);
grossSalary = basicSalary + HRA + DA;
}
else if(basicSalary >= 1500){
grossSalary = basicSalary + (basicSalary*0.98) + 500;
}
console.log( grossSalary );
}
});
Thanks in advance