Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a simple compass program in C language. Write a simple compass program tha

ID: 3796790 • Letter: W

Question

Write a simple compass program in C language.

Write a simple compass program that will input an angle (0 degree to 360 degree) and display the direction (N, NE, E, SE, S, SW, W, and NW). In our simple compass program, the possible directions to be displayed are shown in the following table If the user inputs a negative angle, display an error message. Angles greater than or equal to 360degrees are allowed. Use the modulus operator (%) to convert the input angle to one that is in the range 0to 359 degrees. You may use pseudo code or flow chart for the algorithm for this program. Make sure to test all possible input combinations.

Explanation / Answer

#include <stdio.h>

int main()
{
int d;
  
printf("Enter direction");
scanf("%d",&d);
if(d<0){printf("Donot enter negative values");}
else
{
if(d>360){d=d-360;}
if((d>0 && d<22) || (d>338 && d<359)){printf("The direction is North");}
if(d>22 && d<67){printf("The direction is North East");}
if(d>67 && d<112){printf("The direction is East");}
if(d>112 && d<157){printf("The direction is South East");}
if(d>157 && d<202){printf("The direction is South");}
if(d>202 && d<247){printf("The direction is South West");}
if(d>247 && d<292){printf("The direction is West");}
if(d>292 && d<337){printf("The direction is North West");}
  
  
  
}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote