0
The point is this:
A company will give a salary increase to its employees from according to the category of each employee. The increase will follow the following rule:
Employees in categories A and H will earn 10% increase over salary;
Employees in categories B, D and E will earn 15% increase over salary;
Employees in categories K and R will earn 25% increase over salary;
S category employees will earn 35% increase over salary;
Employees in categories X and Z will earn 50% increase over salary.
Employees in other categories earn 5% increase over salary.
Using the "Switch" command, write a PHP algorithm to receive current category and salary, then display the salary readjusted from an employee to example.
I made this code:
<?php
$salario = 1045;
$salarioFinal = 0;
$percentagem = 0;
$categoria = 'A';
switch ($categoria) {
case 'A' or 'H':
$percentagem = $salario * 10 / 100;
$salarioFinal = $salario + $percentagem;
echo "Salário atual: $salario <br/>";
echo "Salário final: R$ $salarioFinal";
break;
case 'B' or 'D' or 'E';
$percentagem = $salario * 15 / 100;
$salarioFinal = $salario + $percentagem;
echo "Salário atual: $salario <br/>";
echo "Salário final: R$ $salarioFinal";
break;
case 'K' or 'R';
$percentagem = $salario * 25 / 100;
$salarioFinal = $salario + $percentagem;
echo "Salário atual: $salario <br/>";
echo "Salário final: R$ $salarioFinal";
break;
case 'X' or 'Z';
$percentagem = $salario * 50 / 100;
$salarioFinal = $salario + $percentagem;
echo "Salário atual: $salario <br/>";
echo "Salário final: R$ $salarioFinal";
break;
default:
$percentagem = $salario * 5 / 100;
$salarioFinal = $salario + $percentagem;
echo "Salário atual: $salario <br/>";
echo "Salário final: R$ $salarioFinal";
break;
}
?>
The problem is that it always jumps to the default condition by returning:
Salário atual: 1045
Salário final: R$ 1149.5
that is, is not comparing the string according to the variable $categoria = 'A';
declared at the beginning of the code.