-2

I'm having an issue. I have to write a program for my calculator but I'm not sure how to do it. It uses a form of QBASIC language.

My statement is:

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;

I think I could only use (IF, ELSE, THEN)

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
Learner4491
  • 7
  • 2
  • 5
  • 1
    "Here is my assignment, please implement it for me" is not generally allowed / on-topic here; questions are expected to include enough of your own work to show a specific problem you encountered _while trying to write the program yourself_. – Charles Duffy Jun 21 '21 at 22:11

2 Answers2

0

your code is

 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
Monodeep Saha
  • 31
  • 1
  • 3
0

If IF, THEN, and ELSE are all you have then the following applies:

The rule for a statement containing several IFs and ELSEs is that the first ELSE is associated with the closest preceding IF, and each subsequent ELSE with the closest unassigned preceding 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 ---------------------------/

If possible, use the somewhat less complex:

n:=ATAN(y/x): IF y<0 THEN IF x<0 THEN n:=n+180 ELSE n:=n+360 ELSE IF x<0 THEN n:=n+180
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • What your solution omits is the case where either x or y equals zero. The OP never replied, though, so it's hardly worth even answering. – Bill Hileman Jun 28 '21 at 19:39