Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- int main()
- {
- int act_hdg;
- int sel_hdg;
- int turn;
- bool main_loop = true;
- while(main_loop == true)
- {
- printf("Input actual heading ");
- scanf("%d", &act_hdg);
- printf("Input required heading (or 999 to exit) ");
- scanf("%d", &sel_hdg);
- if(sel_hdg == 999)
- main_loop = false;
- turn = sel_hdg - act_hdg;
- if(turn > 180)
- turn = turn - 360;
- if(turn < -180)
- turn = turn + 360;
- printf("Turn is %d\n", turn);
- while(turn != 0)
- {
- if(turn > 0)
- {
- act_hdg++;
- turn--;
- }
- if(turn < 0)
- {
- act_hdg--;
- turn++;
- }
- if(act_hdg > 360)
- act_hdg -= 360;
- if(act_hdg < 1)
- act_hdg += 360;
- printf("Heading is %dº and %dº of turn remain\n", act_hdg, turn);
- usleep(250000);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement