问题描述
我遇到了问题。我必须为我的计算器编写一个程序,但我不知道该怎么做。它使用一种形式的 QBASIC 语言。
我的声明是:
IF (y>0 and x>0) then it should calculate n:=atan(y/x);
IF (y<0 and x<0) then it should calculate n:=atan(y/x)+180;
IF (y>0 and x<0) then it should calculate n:=atan(y/x)+180;
IF (y<0 and x>0) then it should calculate n:=atan(y/x)+360;
我想我只能使用 (IF,ELSE,THEN)
解决方法
您的代码是
cls
input x
input y
if y>0 and x>0 then
n=ATAN(y/x)
else if y<0 and x<0 then
n= ATAN(y/x)+ 180
else if y>0 and x<0 then
n=ATAN(y/x)+180
else if y<0 and x>0 then
n= ATAN(y/x)+360
endif
end
,
如果您只有 IF
、THEN
和 ELSE
,则以下适用:
包含多个 IF
和 ELSE
的语句的规则是第一个 ELSE
与最近的前一个 IF
相关联,每个后续 {{1 }} 前有最接近的未分配 ELSE
。
IF
如果可能,请使用不太复杂的:
first ELSE subsequent ELSE first ELSE
| | |
v v v
IF y<0 THEN IF x<0 THEN n:=ATAN(y/x)+180 ELSE n:=ATAN(y/x)+360 ELSE IF x<0 THEN n:=ATAN(y/x)+180 ELSE n:=ATAN(y/x)
^ ^ | | ^ |
| \--- closest preceding IF ---/ | \--- closest preceding IF ---/
\---unassigned closest preceding IF ---------------------------/