Hi guys..this is for my assignment. the code that i have attempt to do is, i believe it is wrong since it doesn't display the output that i want instead it display all.
i need to use if-else statement and display compass points (such as East,Northeast etc) based on the X and Y entered by the user. i also need to display "no_where" for X==0 and Y==0.
so this is my code..i don't know whether my logic is true or not
thanks for your help in advance
#include <iostream>
usingnamespace std;
int main()
{
float X, Y;
cout << "\t\t\t\t*COMPASS*" << endl << endl;
cout << "This is a compass for you to search for a place if you are lose." << endl;
cout << "This compass can only determine between number -10 to 10 of a circle for X and Y." << endl;
cout << "Enter your X: ";
cin >> X;
cout << endl;
cout << "Enter your Y: ";
cin >> Y;
cout << endl;
if (X == 0)
{
if (Y > 0 && Y <= 10)
cout << "X coordinate: " << X << endl;
cout << "Y coordinate: " << Y << endl;
cout << "You are in: North according to the compass points provided." << endl;
}
elseif (Y < 0 && Y >= -10)
{
cout << "X coordinate: " << X << endl;
cout << "Y coordinate: " << Y << endl;
cout << "You are in: South according to the compass points provided." << endl;
}
if (Y == 0)
{
if (X > 0 && X <= 10)
cout << "X coordinate: " << X << endl;
cout << "Y coordinate: " << Y << endl;
cout << "You are in: East according to the compass points provided." << endl;
}
elseif (Y < 0 && Y >= -10)
{
cout << "X coordinate: " << X << endl;
cout << "Y coordinate: " << Y << endl;
cout << "You are in: West according to the compass points provided." << endl;
}
if (X > 0 && X <= 10)
{
if (Y > 0 && Y <= 10)
cout << "X coordinate: " << X << endl;
cout << "Y coordinate: " << Y << endl;
cout << "You are in: Northeast according to the compass points provided." << endl;
}
elseif (Y < 0 && Y >= -10)
{
cout << "X coordinate: " << X << endl;
cout << "Y coordinate: " << Y << endl;
cout << "You are in: Southeast according to the compass points provided." << endl;
}
if (X < 0 && X >= -10)
{
if (Y > 0 && Y <= 10)
cout << "X coordinate: " << X << endl;
cout << "Y coordinate: " << Y << endl;
cout << "You are in: Northwest according to the compass points provided." << endl;
}
else
{
cout << "X coordinate: " << X << endl;
cout << "Y coordinate: " << Y << endl;
cout << "You are in: Southwest according to the compass points provided." << endl;
}
if (X == 0 && Y == 0)
{
cout << "No_where" << endl;
}
return 0;
}