diff --git a/exercises/037_structs.zig b/exercises/037_structs.zig index c345faf..1aa56f9 100644 --- a/exercises/037_structs.zig +++ b/exercises/037_structs.zig @@ -36,6 +36,7 @@ const Character = struct { role: Role, gold: u32, experience: u32, + health: u8, }; pub fn main() void { @@ -44,6 +45,7 @@ pub fn main() void { .role = Role.wizard, .gold = 20, .experience = 10, + .health = 100, }; // Glorp gains some gold. diff --git a/exercises/038_structs2.zig b/exercises/038_structs2.zig index b9d84aa..5f1f4d1 100644 --- a/exercises/038_structs2.zig +++ b/exercises/038_structs2.zig @@ -43,6 +43,13 @@ pub fn main() void { // Feel free to run this program without adding Zump. What does // it do and why? + chars[1] = Character{ + .role = Role.bard, + .gold = 10, + .health = 100, + .experience = 20, + }; + // Printing all RPG characters in a loop: for (chars, 0..) |c, num| { std.debug.print("Character {} - G:{} H:{} XP:{}\n", .{ diff --git a/exercises/039_pointers.zig b/exercises/039_pointers.zig index 24ca46d..392dbf4 100644 --- a/exercises/039_pointers.zig +++ b/exercises/039_pointers.zig @@ -30,7 +30,7 @@ pub fn main() void { // Please make num2 equal 5 using num1_pointer! // (See the "cheatsheet" above for ideas.) - num2 = ???; + num2 = num1_pointer.*; std.debug.print("num1: {}, num2: {}\n", .{ num1, num2 }); } diff --git a/exercises/040_pointers2.zig b/exercises/040_pointers2.zig index a4852f6..e54888d 100644 --- a/exercises/040_pointers2.zig +++ b/exercises/040_pointers2.zig @@ -23,7 +23,7 @@ const std = @import("std"); pub fn main() void { const a: u8 = 12; - const b: *u8 = &a; // fix this! + const b: *const u8 = &a; // fix this! std.debug.print("a: {}, b: {}\n", .{ a, b.* }); } diff --git a/exercises/041_pointers3.zig b/exercises/041_pointers3.zig index 9e2bcc6..5b63d71 100644 --- a/exercises/041_pointers3.zig +++ b/exercises/041_pointers3.zig @@ -31,7 +31,7 @@ pub fn main() void { // Please define pointer "p" so that it can point to EITHER foo or // bar AND change the value it points to! - ??? p: ??? = undefined; + var p: *u8 = undefined; p = &foo; p.* += 1; diff --git a/exercises/042_pointers4.zig b/exercises/042_pointers4.zig index 1f6db70..1ecc1f3 100644 --- a/exercises/042_pointers4.zig +++ b/exercises/042_pointers4.zig @@ -37,5 +37,5 @@ pub fn main() void { // This function should take a reference to a u8 value and set it // to 5. fn makeFive(x: *u8) void { - ??? = 5; // fix me! + x.* = 5; // fix me! } diff --git a/exercises/043_pointers5.zig b/exercises/043_pointers5.zig index 9e2fa6f..23ee2e2 100644 --- a/exercises/043_pointers5.zig +++ b/exercises/043_pointers5.zig @@ -68,7 +68,7 @@ pub fn main() void { // FIX ME! // Please pass Glorp to printCharacter(): - printCharacter(???); + printCharacter(&glorp); } // Note how this function's "c" parameter is a pointer to a Character struct. diff --git a/exercises/044_quiz5.zig b/exercises/044_quiz5.zig index 8a0d88c..3e6ee79 100644 --- a/exercises/044_quiz5.zig +++ b/exercises/044_quiz5.zig @@ -19,12 +19,14 @@ const Elephant = struct { pub fn main() void { var elephantA = Elephant{ .letter = 'A' }; // (Please add Elephant B here!) + var elephantB = Elephant{ .letter = 'B' }; var elephantC = Elephant{ .letter = 'C' }; // Link the elephants so that each tail "points" to the next elephant. // They make a circle: A->B->C->A... elephantA.tail = &elephantB; // (Please link Elephant B's tail to Elephant C here!) + elephantB.tail = &elephantC; elephantC.tail = &elephantA; visitElephants(&elephantA); diff --git a/exercises/045_optionals.zig b/exercises/045_optionals.zig index 494c960..1763f6b 100644 --- a/exercises/045_optionals.zig +++ b/exercises/045_optionals.zig @@ -29,7 +29,7 @@ pub fn main() void { // Please threaten the result so that answer is either the // integer value from deepThought() OR the number 42: - const answer: u8 = result; + const answer: u8 = result orelse 42; std.debug.print("The Ultimate Answer: {}.\n", .{answer}); } diff --git a/exercises/046_optionals2.zig b/exercises/046_optionals2.zig index d3f65bb..77b7f24 100644 --- a/exercises/046_optionals2.zig +++ b/exercises/046_optionals2.zig @@ -21,7 +21,7 @@ const std = @import("std"); const Elephant = struct { letter: u8, - tail: *Elephant = null, // Hmm... tail needs something... + tail: ?*Elephant = null, // Hmm... tail needs something... visited: bool = false, }; @@ -51,7 +51,7 @@ fn visitElephants(first_elephant: *Elephant) void { // We should stop once we encounter a tail that // does NOT point to another element. What can // we put here to make that happen? - if (e.tail == null) ???; + if (e.tail == null) break; e = e.tail.?; }