IF 语句程序

问题描述

我遇到了问题。我必须为我的计算器编写一个程序,但我不知道该怎么做。它使用一种形式的 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
,

如果您只有 IFTHENELSE,则以下适用:

包含多个 IFELSE 的语句的规则是第一个 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 ---------------------------/

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...