Write a program that prompts the user to input the x-y coordinate of a point in a Cartesian plane.
The program should then output a message indicating whether the point is the origin, is located
on the x-axis or y-axis, or appears in particular quadrant (1st quadrant, 2nd quadrant, 3rd quadrant
or 4th quadrant).
#include <iostream>
using namespace std;
int main()
{
int x, y;
cout << "Enter x and y: ";
cin >> x >> y;
if (x == 0 && y == 0)
cout << "Point is the origin";
else if (y == 0) //if y is 0 then x != 0 otherwise point would be the origin
cout << "Point located on x-axis";
else if (x == 0)
cout << "Point located on y-axis";
else if (y > 0) {
if (x > 0)
cout << "Point is a part of first quadrant";
else
cout << "Point is a part of second quadrant";
}
else { /*we don't need to check if y < 0 because we already know that
y != 0 and y isn't positive*/
if (x < 0)
cout << "Point is a part of third quadrant";
else
cout << "Point is a part of fourth quadrant";
}
cout << endl;
return 0;
}
I'm not sure if it okay for you to use "using namespace std", usually it's okay for learning purposes, but if it's not, then that line should be removed and:
how code should be changed:
cin to std::cin
cout to std::cout
end to std::endl
Comments
Thank you!!!!
Leave a comment