A35
A35

Reputation: 1

SmallBasic calculate monthly salary for employees

I need to set overtime hours to 0 if a negative number is entered and if the overtime hours is greater than 20 set it to 20. I entered it as follows

TextWindow.Write(" Enter the number of overtime hours: ")
overtime = TextWindow.ReadNumber()
If (overtime < 0 Or overtime > 20) Then 
TextWindow.WriteLine("Invalid hours. Hours must be between 0 and 20")
EndIf

I believe I'm doing it wrong but I do not know how to fix it.

Upvotes: 0

Views: 118

Answers (2)

Matthew
Matthew

Reputation: 155

what you could do is, make two if statements,

if overtime<0 then
overtime = 0
else if overtime > 20 then
overtime = 20
endif

endif

Upvotes: 1

Ketan Ahir
Ketan Ahir

Reputation: 6738

I don't know anything about smallbasic but here is simple logic

Assuming you want to set overtime=0 when entered number is negative and overtime=20 when entered number is greater than 20;

If (overtime < 0 ) Then 
  TextWindow.WriteLine("Invalid hours. Hours must be greater than 0")
  overtime =0
Else If (overtime > 20 ) Then 
  TextWindow.WriteLine("Invalid hours. Hours must be less than 20")
  overtime =20
Else
   //do your stuff here
EndIf

Upvotes: 1

Related Questions