Algorithm Salary Readjust !!!

Este forum é destinado a perguntas relacionadas a Oracle, mas que não se enquadram nos forums acima. Aqui serão tratadas também sobre outras tecnologias da oracle, como o Workflow, BPEL, Spatial, OCS, etc.
Post Reply
edu1333
Rank: Programador Pleno
Rank: Programador Pleno
Posts: 31
Joined: Fri, 13 Jun 2008 10:49 pm
Location: São Paulo- SP

Good morning !!!

I am inner in programming logic and I need a help to solve an algorithm, to resolve the readjustments of a salary.
Is the code as follows?

Select all

 
var 
a,r,t,w: real 
inicio 
// Seção de Comandos  
escreva("Digite o salario: ") 
leia(a) 
se a <= 500 então 
r:= a*(15/100) 
escreval(" Seu salário reajustado em 15% é: ", r) 
senao se a > 500 e a <= 1000 então 
t:= a*(10/100) 
escreval(" Seu salário reajustado em 10% é: ", t) 
se a > 1000 então 
w:= a*(5/100) 
escreval(" Seu salário reajustado em 5% é: ", w) 
fimse 
fimse
The code Verifies the readjustment according to the salary, but when I put a salary greater than 1000 it calculates the 10% and 5%, but it should not be 1000 is only 5%, please help me ???

Hugs !!!

Eduardo
RodrigoValentim
Moderador
Moderador
Posts: 367
Joined: Tue, 25 Mar 2008 3:41 pm
Location: Salvador - BA
Rodrigo Valentim
Analista de Sistemas
Oracle Developer

Campanha: Faça uma pesquisa antes de perguntar!!!

For conditions like this, we use the following ...

Select all

if 1 = 2 then 
  (...) 
elsif 1 = 3 then 
  (...) 
elsif 1 = 4 then 
  (...) 
elsif 1=5 then 
  (...) 
elsif 1 = 1 then 
  (...) 
else  
nenhum igual 
end if;
In your case, you put the following routine ... and avoids it to enter into Two IF's

Select all

var  
a,r,t,w: real  
inicio  
// Seção de Comandos  
   escreva("Digite o salario: ")  
   leia(a)  
se a <= 500 então  
   r:= a*(15/100)  
   escreval(" Seu salário reajustado em 15% é: ", r)  
senao  
   se a > 500 e a <= 1000 então  
      t:= a*(10/100)  
      escreval(" Seu salário reajustado em 10% é: ", t)  
   senao  
      se a > 1000 então  
        w:= a*(5/100)  
        escreval(" Seu salário reajustado em 5% é: ", w)  
      fimse  
   fimse 
fimse 
However, in its routine still needs an adjustment ...

1. No need to use 3 variables, with a variable only it is possible to do what you want.

Select all

var  
a,r: real  
inicio  
// Seção de Comandos  
   escreva("Digite o salario: ")  
   leia(a)  
se a <= 500 então --Se for menor igual a 500, entre 
   a:= a*(15/100)  
   escreval(" Seu salário reajustado em 15% é: ", a)  
senao --se não for menor igual a 500, entre aqui...  
   se a > 500 e a <= 1000 então --Se for maior que 500 e menor igual a 100, entre... 
      a:= a*(10/100)  
      escreval(" Seu salário reajustado em 10% é: ", a)  
   senao --senao for maior que 500 e menor igual a 100...  
      se a > 1000 -- então então ele é maior que 1000 
        a:= a*(5/100)  
        escreval(" Seu salário reajustado em 5% é: ", a)  
      fimse  
   fimse 
fimse 
I think that's it!
alexrsilva
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 153
Joined: Tue, 27 May 2008 1:31 pm
Location: Rio de Janeiro - RJ

When you have few options for validating, the IF is a good option. Now think that you have more than 10 checks to do?
Use the CASE that decreases the code and makes understanding easier for future maintenance.

Select all

ler (x); 
case x 
when 100: 
codigo;  
break; dependendo da linguagem 
when 200: 
codigo; 
break; 
else 
codigo; 
end case;
has the case with limits

Select all

case 
when x>100 and x< 500 then 
codigo; 
end case;

Att,

Alex Silva
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest