RosettaCodeData/Task/Box-the-compass/Zig/box-the-compass-3.zig

17 lines
487 B
Zig
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
pub fn main() anyerror!void {
const stdout = std.io.getStdOut().writer();
2023-09-16 17:28:03 -07:00
try stdout.print("Index Heading Compass point\n", .{});
2023-07-01 11:58:00 -04:00
for (0..33) |i| {
2023-09-16 17:28:03 -07:00
var heading = @as(f32, @floatFromInt(i)) * 11.25;
2023-07-01 11:58:00 -04:00
heading += switch (i % 3) {
1 => 5.62,
2 => -5.62,
else => 0,
};
const index = i % 32 + 1;
2023-09-16 17:28:03 -07:00
try stdout.print(" {d:2} {d:>6.2}° {s}\n", .{ index, heading, degreesToCompassPoint(heading) });
2023-07-01 11:58:00 -04:00
}
}