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). For example:
a. (0, 0) is the origin
b. (4, 0) is on the x-axis
c. (0, -3) is on the y-axis
d. (-2, 3) is in the 2nd quadrant
Print the output for 7 different inputs; the origin, x-axis, y-axis, 1st quadrant, 2nd quadrant, 3rd quadrant or 4th quadrant.
#include <iostream>
using namespace std;
int main() {
cout << "x: ";
int x = 0;
cin >> x;
cout << "y: ";
int y = 0;
cin >> y;
if (x == 0 && y == 0) {
cout << "the origin" << endl;
}
if (x == 0 && y != 0) {
cout << "the y-axis" << endl;
}
if (x != 0 && y == 0) {
cout << "the x-axis" << endl;
}
if (x > 0 && y > 0) {
cout << "1st quadrant" << endl;
}
if (x < 0 && y > 0) {
cout << "2nd quadrant" << endl;
}
if (x < 0 && y < 0) {
cout << "3rd quadrant" << endl;
}
if (x > 0 && y < 0) {
cout << " 4th quadrant" << endl;
}
return 0;
}
Comments
Leave a comment