My code is printing some pretty wild results and im not sure what in my code is causing this.
An example for what my serial monitor reads is
"
Enter a value for x
Your x coordinate is 2
Enter a value for y
Your y coordinate is 3
2 is in quadrant 1
2 is in quadrant 3
2 is on the x-axis "
Why all the different outputs?
Thanks in advance
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //setup serial communication
}
void loop() {
// put your main code here, to run repeatedly:
int x, y;
Serial.println("\nEnter a value for x");
while (Serial.available() <= 0);
x = Serial.parseInt();
Serial.print("Your x coordinate is ");
Serial.print(x);
Serial.println("\nEnter a value for y");
while (Serial.available() <= 0);
y = Serial.parseInt();
Serial.print("Your y coordinate is ");
Serial.println(y);
if (x != 0 && y != 0)
{
if (x > 0 && y > 0)
{
Serial.print(x,y);
Serial.println(" is in quadrant 1");
}
else if (x > 0 && y < 0)
{
Serial.print(x,y);
Serial.println(" is in quadrant 4");
}
else if (x < 0 && y > 0)
{
Serial.print(x,y);
Serial.println(" is in quadrant 2");
}
else (x < 0 && y < 0);
{
Serial.print(x,y);
Serial.println(" is in quadrant 3");
}
}
if (x == 0 && y != 0)
{
Serial.print(x,y);
Serial.println(" is on the y axis");
}
else if (x != 0 && y == 0);
{
Serial.print(x,y);
Serial.println(" is on the x axis");
}
}