如果输入负数,则我需要将加班时间设置为0,如果加班时间大于20,则将其设置为20。我按以下输入
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
我相信我做错了,但我不知道如何修复它。
我对smallbasic一无所知,但这里有一个简单的逻辑
假设输入的数字为负数时要设置overtime=0
,输入的数字大于20时设置overtime=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
您可以做的是,生成两个if语句,
if overtime<0 then
overtime = 0
else if overtime > 20 then
overtime = 20
endif
endif