diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-02-07 11:06:51 -0500 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-02-07 11:06:51 -0500 |
commit | adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a (patch) | |
tree | a25511c3bb20069f1d6123366573c82c5745338b /03_assignment.zig | |
parent | 507355ec3b1066c707e19816b86ac1fb56fc0385 (diff) | |
download | ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.gz ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.bz2 ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.xz ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.zip |
Consistent instructions and examples
I started off with "hints" that required the poor student to piece
together the information from incomplete bits. A complete example is
like a picture that is worth 1000 words and far clearer.
Diffstat (limited to '03_assignment.zig')
-rw-r--r-- | 03_assignment.zig | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/03_assignment.zig b/03_assignment.zig index 2c4c15a..d26f2a2 100644 --- a/03_assignment.zig +++ b/03_assignment.zig @@ -1,14 +1,32 @@ // -// Oh dear! It seems we got a little carried away making const u8 values. -// * const means constant (cannot be changed) -// * u8 means unsigned (cannot be negative), 8-bit integer -// -// Hint 1: Use 'var' for values that can change. -// Hint 2: Use enough bits to hold the value you want: -// u8 255 -// u16 65,535 -// u32 4,294,967,295 -// Hint 3: Use 'i' (e.g. 'i8', 'i16') for signed integers. +// 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; +// var bar: i8 = -20; +// +// Example: foo can hold 8 bits (0 to 255) +// bar can hold 16 bits (0 to 65,535) +// +// 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"); |