如果输入负数,我需要将加班时间设置为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
我相信我做错了但我不知道如何解决它。
答案 0 :(得分:1)
我对小基础知之甚少,但这里的逻辑很简单
假设您要在输入的数字为负数时设置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
答案 1 :(得分:1)
你可以做的是,制作两个if语句,
if overtime<0 then
overtime = 0
else if overtime > 20 then
overtime = 20
endif
ENDIF