Advertisement
KeithS

Basic Turn Procedure

Jun 18th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3.  
  4. int main()
  5. {
  6.     int act_hdg;
  7.     int sel_hdg;
  8.     int turn;
  9.     bool main_loop = true;
  10.  
  11.     while(main_loop == true)
  12.     {
  13.         printf("Input actual heading ");
  14.         scanf("%d", &act_hdg);
  15.         printf("Input required heading (or 999 to exit) ");
  16.         scanf("%d", &sel_hdg);
  17.  
  18.         if(sel_hdg == 999)
  19.             main_loop = false;
  20.  
  21.         turn = sel_hdg - act_hdg;
  22.  
  23.         if(turn > 180)
  24.             turn = turn - 360;
  25.         if(turn < -180)
  26.             turn = turn + 360;
  27.  
  28.         printf("Turn is %d\n", turn);
  29.  
  30.         while(turn != 0)
  31.         {
  32.             if(turn > 0)
  33.             {
  34.                 act_hdg++;
  35.                 turn--;
  36.             }
  37.             if(turn < 0)
  38.             {
  39.                 act_hdg--;
  40.                 turn++;
  41.             }
  42.             if(act_hdg > 360)
  43.                 act_hdg -= 360;
  44.             if(act_hdg < 1)
  45.                 act_hdg += 360;
  46.  
  47.             printf("Heading is %dº and %dº of turn remain\n", act_hdg, turn);
  48.             usleep(250000);
  49.         }
  50.         printf("\n");
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement