# I keep getting a syntax error with my program???

11 views (last 30 days)
Aaron on 28 Jun 2012
I'm creating a program that identifies x and y coordinates in a Cartesian coordinate system.
x=input('Enter value for x: '); y=input('Enter value for y: '); if x=0 & y=0 disp('This point is located at the origin.') elseif x>0 & y=0 fprintf disp('This point is located on the x-axis.') elseif x=0 & y>0 disp('This point is located on the y-axis.') elseif x>0 & y>0 disp('This point is located in the first quadrant.') elseif x<0 & y>0 disp('This point is located in the second quadrant.') elseif x<0 & y<0 disp('This point is located in the third quadrant.') elseif x>0 & y<0 disp('This point is located in the fourth quadrant.') end
I keep getting a syntax error with the x=0? The error tells me that '=' might be invalid Matlab syntax.
What am I doing wrong?
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Thomas on 28 Jun 2012
Edited: Thomas on 28 Jun 2012
in the If statement you need to use '==' Your first if statement would be
if x==0 & y==0
disp('This point is located at the origin.')
Your entire code
x=input('Enter value for x: ');
y=input('Enter value for y: ');
if x==0 & y==0
disp('This point is located at the origin.')
elseif x>0 & y==0
disp('This point is located on the x-axis.')
elseif x==0 & y>0
disp('This point is located on the y-axis.')
elseif x>0 & y>0
disp('This point is located in the first quadrant.')
elseif x<0 & y>0
disp('This point is located in the second quadrant.')
elseif x<0 & y<0
disp('This point is located in the third quadrant.')
elseif x>0 & y<0
disp('This point is located in the fourth quadrant.')
end
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### More Answers (1)

Wayne King on 28 Jun 2012
x=input('Enter value for x: ');
y=input('Enter value for y: ');
if x==0 & y==0 disp('This point is located at the origin.')
elseif x>0 & y==0 fprintf disp('This point is located on the x-axis.')
elseif x==0 & y>0 disp('This point is located on the y-axis.')
elseif x>0 & y>0 disp('This point is located in the first quadrant.')
elseif x<0 & y>0 disp('This point is located in the second quadrant.')
elseif x<0 & y<0 disp('This point is located in the third quadrant.')
elseif x>0 & y<0 disp('This point is located in the fourth quadrant.'); end
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!