Print out the 8 points of the compass, based on the x and y components of the direction of travel.

Print out the 8 points of the compass, based on the x and y components of the direction of travel.

if(x > 0)
{
if(y > 0)
printf("Northeast.\n");
else if(y < 0)
printf("Southeast.\n");
else printf("East.\n");
}
else if(x < 0)
{
if(y > 0)
printf("Northwest.\n");
else if(y < 0)
printf("Southwest.\n");
else printf("West.\n");
}
else {
if(y > 0)
printf("North.\n");
else if(y < 0)
printf("South.\n");
else printf("Nowhere.\n");
}

No comments:

Post a Comment