Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,959 questions

51,901 answers

573 users

How to convert a degree to a compass direction in Pascal

1 Answer

0 votes
program CompassDirection;

uses
  Math;  { for frac and floor if needed, but we'll keep it simple }

const
  Directions: array[0..7] of string =
    ('North', 'North-East', 'East', 'South-East',
     'South', 'South-West', 'West', 'North-West');

function DegreesToDirection(degrees: Real): string;
var
  index: Integer;
begin
  { Normalize degrees to (0, 360) }
  degrees := degrees + 360;
  degrees := degrees - Int(degrees / 360) * 360;

  { Each direction covers 45 degrees }
  //index := Round(degrees / 45) mod 8;
  index := Round(degrees / 22.5) mod 8;

  DegreesToDirection := Directions[index];
end;

var
  degrees: Real;
begin
  degrees := 120;
  WriteLn('For ', degrees:0:0, ' degrees, Compass direction: ', DegreesToDirection(degrees));
end.



(*
run:

For 120 degrees, Compass direction: South-East

*)

 



answered Nov 24, 2025 by avibootz
edited Nov 24, 2025 by avibootz
...