summaryrefslogtreecommitdiffstatshomepage
path: root/exercises/003_assignment.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-03-12 18:59:46 -0500
committerDave Gauer <dave@ratfactor.com>2021-03-12 18:59:46 -0500
commit0956f1839fcaaa273353148da9e157a8f9690d2f (patch)
treed6c90700131d5b28e898881f13e2a05612e4703f /exercises/003_assignment.zig
parent93eefe0f250bb76bfdd8e6bb784b6a9586517000 (diff)
"999 is enough for anybody" triple-zero padding (#18)
When I hit 999 exercises, I will finally have reached the ultimate state of soteriological release and no more exercises will be needed. The cycle will be complete. All that will be left is perfect quietude, freedom, and highest happiness.
Diffstat (limited to 'exercises/003_assignment.zig')
-rw-r--r--exercises/003_assignment.zig51
1 files changed, 51 insertions, 0 deletions
diff --git a/exercises/003_assignment.zig b/exercises/003_assignment.zig
new file mode 100644
index 0000000..6a4364b
--- /dev/null
+++ b/exercises/003_assignment.zig
@@ -0,0 +1,51 @@
+//
+// It seems we got a little carried away making everything "const u8"!
+//
+// "const" values cannot change.
+// "u" types are "unsigned" and cannot store negative values.
+// "8" means the type is 8 bits in size.
+//
+// Example: foo cannot change (it is CONSTant)
+// bar can change (it is VARiable):
+//
+// const foo: u8 = 20;
+// var bar: u8 = 20;
+//
+// Example: foo cannot be negative and can hold 0 to 255
+// bar CAN be negative and can hold −128 to 127
+//
+// const foo: u8 = 20;
+// const bar: i8 = -20;
+//
+// Example: foo can hold 8 bits (0 to 255)
+// bar can hold 16 bits (0 to 65,535)
+//
+// const foo: u8 = 20;
+// const bar: u16 = 2000;
+//
+// You can do just about any combination of these that you can think of:
+//
+// u32 can hold 0 to 4,294,967,295
+// i64 can hold −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
+//
+// Please fix this program so that the types can hold the desired values
+// and the errors go away!
+//
+const std = @import("std");
+
+pub fn main() void {
+ const n: u8 = 50;
+ n = n + 5;
+
+ const pi: u8 = 314159;
+
+ const negative_eleven: u8 = -11;
+
+ // There are no errors in the next line, just explanation:
+ // Perhaps you noticed before that the print function takes two
+ // parameters. Now it will make more sense: the first parameter
+ // is a string. The string may contain placeholders '{}', and the
+ // second parameter is an "anonymous list literal" (don't worry
+ // about this for now!) with the values to be printed.
+ std.debug.print("{} {} {}\n", .{ n, pi, negative_eleven });
+}