diff options
author | Martin Ashby <martin@ashbysoft.com> | 2022-12-10 23:02:40 +0000 |
---|---|---|
committer | Martin Ashby <martin@ashbysoft.com> | 2022-12-10 23:02:40 +0000 |
commit | 5257941f40554da3f8df074443a4c087dcff7004 (patch) | |
tree | b55af272f52f961f8fa02468861de2c255d8a9e2 /exercises | |
parent | 0e447c7956410a993614f9337d6219e017722443 (diff) | |
download | ziglings-5257941f40554da3f8df074443a4c087dcff7004.tar.gz ziglings-5257941f40554da3f8df074443a4c087dcff7004.tar.bz2 ziglings-5257941f40554da3f8df074443a4c087dcff7004.tar.xz ziglings-5257941f40554da3f8df074443a4c087dcff7004.zip |
25-60 completemain
Diffstat (limited to 'exercises')
36 files changed, 95 insertions, 74 deletions
diff --git a/exercises/025_errors5.zig b/exercises/025_errors5.zig index 8739e4a..9759a70 100644 --- a/exercises/025_errors5.zig +++ b/exercises/025_errors5.zig @@ -26,7 +26,7 @@ fn addFive(n: u32) MyNumberError!u32 { // This function needs to return any error which might come back from detect(). // Please use a "try" statement rather than a "catch". // - var x = detect(n); + var x = try detect(n); return x + 5; } diff --git a/exercises/026_hello2.zig b/exercises/026_hello2.zig index cb29193..af840f2 100644 --- a/exercises/026_hello2.zig +++ b/exercises/026_hello2.zig @@ -18,5 +18,5 @@ pub fn main() !void { // to be able to pass it up as a return value of main(). // // We just learned of a single statement which can accomplish this. - stdout.print("Hello world!\n", .{}); + try stdout.print("Hello world!\n", .{}); } diff --git a/exercises/027_defer.zig b/exercises/027_defer.zig index b41e2af..68d0974 100644 --- a/exercises/027_defer.zig +++ b/exercises/027_defer.zig @@ -20,6 +20,6 @@ const std = @import("std"); pub fn main() void { // Without changing anything else, please add a 'defer' statement // to this code so that our program prints "One Two\n": - std.debug.print("Two\n", .{}); + defer std.debug.print("Two\n", .{}); std.debug.print("One ", .{}); } diff --git a/exercises/028_defer2.zig b/exercises/028_defer2.zig index 35c1326..358fe28 100644 --- a/exercises/028_defer2.zig +++ b/exercises/028_defer2.zig @@ -18,7 +18,7 @@ pub fn main() void { fn printAnimal(animal: u8) void { std.debug.print("(", .{}); - std.debug.print(") ", .{}); // <---- how?! + defer std.debug.print(") ", .{}); // <---- how?! if (animal == 'g') { std.debug.print("Goat", .{}); diff --git a/exercises/029_errdefer.zig b/exercises/029_errdefer.zig index 82fdfe1..6747b5b 100644 --- a/exercises/029_errdefer.zig +++ b/exercises/029_errdefer.zig @@ -32,7 +32,7 @@ fn makeNumber() MyErr!u32 { // Please make the "failed" message print ONLY if the makeNumber() // function exits with an error: - std.debug.print("failed!\n", .{}); + errdefer std.debug.print("failed!\n", .{}); var num = try getNumber(); // <-- This could fail! diff --git a/exercises/030_switch.zig b/exercises/030_switch.zig index cb983f5..04e6b6d 100644 --- a/exercises/030_switch.zig +++ b/exercises/030_switch.zig @@ -46,6 +46,7 @@ pub fn main() void { // match for every possible value). Please add an "else" // to this switch to print a question mark "?" when c is // not one of the existing matches. + else => std.debug.print("?", .{}), } } diff --git a/exercises/031_switch2.zig b/exercises/031_switch2.zig index d8af6e6..acbea46 100644 --- a/exercises/031_switch2.zig +++ b/exercises/031_switch2.zig @@ -31,6 +31,7 @@ pub fn main() void { 26 => 'Z', // As in the last exercise, please add the 'else' clause // and this time, have it return an exclamation mark '!'. + else => '!', }; std.debug.print("{c}", .{real_char}); diff --git a/exercises/032_unreachable.zig b/exercises/032_unreachable.zig index ffc35a4..7fe5fc1 100644 --- a/exercises/032_unreachable.zig +++ b/exercises/032_unreachable.zig @@ -35,6 +35,7 @@ pub fn main() void { 3 => { current_value *= current_value; }, + else => unreachable, } std.debug.print("{} ", .{current_value}); diff --git a/exercises/033_iferror.zig b/exercises/033_iferror.zig index 6ba0c61..d9fd177 100644 --- a/exercises/033_iferror.zig +++ b/exercises/033_iferror.zig @@ -40,6 +40,7 @@ pub fn main() void { } else |err| switch (err) { MyNumberError.TooBig => std.debug.print(">4. ", .{}), // Please add a match for TooSmall here and have it print: "<4. " + MyNumberError.TooSmall => std.debug.print("<4. ", .{}), } } diff --git a/exercises/034_quiz4.zig b/exercises/034_quiz4.zig index 2d843f2..5ff4423 100644 --- a/exercises/034_quiz4.zig +++ b/exercises/034_quiz4.zig @@ -9,10 +9,10 @@ const std = @import("std"); const NumError = error{IllegalNumber}; -pub fn main() void { +pub fn main() !void { const stdout = std.io.getStdOut().writer(); - const my_num: u32 = getNumber(); + const my_num: u32 = try getNumber(); try stdout.print("my_num={}\n", .{my_num}); } diff --git a/exercises/035_enums.zig b/exercises/035_enums.zig index 1825f52..da0e415 100644 --- a/exercises/035_enums.zig +++ b/exercises/035_enums.zig @@ -20,7 +20,7 @@ const std = @import("std"); // Please complete the enum! -const Ops = enum { ??? }; +const Ops = enum { inc, pow, dec }; pub fn main() void { const operations = [_]Ops{ diff --git a/exercises/036_enums2.zig b/exercises/036_enums2.zig index 820a71e..c1e5c9b 100644 --- a/exercises/036_enums2.zig +++ b/exercises/036_enums2.zig @@ -31,7 +31,7 @@ const std = @import("std"); const Color = enum(u32) { red = 0xff0000, green = 0x00ff00, - blue = ???, + blue = 0x0000ff, }; pub fn main() void { @@ -53,12 +53,12 @@ pub fn main() void { \\<p> \\ <span style="color: #{x:0>6}">Red</span> \\ <span style="color: #{x:0>6}">Green</span> - \\ <span style="color: #{}">Blue</span> + \\ <span style="color: #{x:0>6}">Blue</span> \\</p> \\ , .{ @enumToInt(Color.red), @enumToInt(Color.green), - @enumToInt(???), // Oops! We're missing something! + @enumToInt(Color.blue), }); } diff --git a/exercises/037_structs.zig b/exercises/037_structs.zig index 32f7b41..0b6242f 100644 --- a/exercises/037_structs.zig +++ b/exercises/037_structs.zig @@ -36,15 +36,12 @@ const Character = struct { class: Class, gold: u32, experience: u32, + health: u8, }; pub fn main() void { // Please initialize Glorp with 100 health. - var glorp_the_wise = Character{ - .class = Class.wizard, - .gold = 20, - .experience = 10, - }; + var glorp_the_wise = Character{ .class = Class.wizard, .gold = 20, .experience = 10, .health = 100 }; // Glorp gains some gold. glorp_the_wise.gold += 5; diff --git a/exercises/038_structs2.zig b/exercises/038_structs2.zig index 4f2ce48..82cfa4a 100644 --- a/exercises/038_structs2.zig +++ b/exercises/038_structs2.zig @@ -42,6 +42,12 @@ pub fn main() void { // // Feel free to run this program without adding Zump. What does // it do and why? + chars[1] = Character{ + .class = Class.bard, + .gold = 10, + .health = 100, + .experience = 20, + }; // Printing all RPG characters in a loop: for (chars) |c, num| { diff --git a/exercises/039_pointers.zig b/exercises/039_pointers.zig index d545525..2eb5b22 100644 --- a/exercises/039_pointers.zig +++ b/exercises/039_pointers.zig @@ -30,7 +30,8 @@ pub fn main() void { // Please make num2 equal 5 using num1_pointer! // (See the "cheatsheet" above for ideas.) - num2 = ???; + //num2 = num1_pointer.*; + num2 = num1_pointer.*; std.debug.print("num1: {}, num2: {}\n", .{ num1, num2 }); } diff --git a/exercises/040_pointers2.zig b/exercises/040_pointers2.zig index 43dd2c3..dcbf9a1 100644 --- a/exercises/040_pointers2.zig +++ b/exercises/040_pointers2.zig @@ -21,7 +21,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 359a2f1..1210095 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 1327e4c..b38e4ee 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: - var answer: u8 = result; + var 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.?; } diff --git a/exercises/047_methods.zig b/exercises/047_methods.zig index 0e7bfa8..67000ba 100644 --- a/exercises/047_methods.zig +++ b/exercises/047_methods.zig @@ -89,7 +89,7 @@ pub fn main() void { for (aliens) |*alien| { // *** Zap the alien with the heat ray here! *** - ???.zap(???); + heat_ray.zap(alien); // If the alien's health is still above 0, it's still alive. if (alien.health > 0) aliens_alive += 1; diff --git a/exercises/048_methods2.zig b/exercises/048_methods2.zig index 310867a..d8d72d4 100644 --- a/exercises/048_methods2.zig +++ b/exercises/048_methods2.zig @@ -54,7 +54,7 @@ fn visitElephants(first_elephant: *Elephant) void { // This gets the next elephant or stops. if (e.hasTail()) { - e = e.???; // Which method do we want here? + e = e.getTail(); // Which method do we want here? } else { break; } diff --git a/exercises/049_quiz6.zig b/exercises/049_quiz6.zig index 92541a5..fd358ec 100644 --- a/exercises/049_quiz6.zig +++ b/exercises/049_quiz6.zig @@ -27,7 +27,13 @@ const Elephant = struct { // Your Elephant trunk methods go here! // --------------------------------------------------- - ??? + pub fn hasTrunk(self: *Elephant) bool { + return self.trunk != null; + } + + pub fn getTrunk(self: *Elephant) *Elephant { + return self.trunk.?; + } // --------------------------------------------------- diff --git a/exercises/050_no_value.zig b/exercises/050_no_value.zig index 8c73ed3..80d20eb 100644 --- a/exercises/050_no_value.zig +++ b/exercises/050_no_value.zig @@ -65,10 +65,10 @@ const std = @import("std"); const Err = error{Cthulhu}; pub fn main() void { - var first_line1: *const [16]u8 = ???; + var first_line1: *const [16]u8 = undefined; first_line1 = "That is not dead"; - var first_line2: Err!*const [21]u8 = ???; + var first_line2: Err!*const [21]u8 = Err.Cthulhu; first_line2 = "which can eternal lie"; // Note we need the "{!s}" format for the error union string. @@ -77,8 +77,8 @@ pub fn main() void { printSecondLine(); } -fn printSecondLine() ??? { - var second_line2: ?*const [18]u8 = ???; +fn printSecondLine() void { + var second_line2: ?*const [18]u8 = null; second_line2 = "even death may die"; std.debug.print("And with strange aeons {s}.\n", .{second_line2.?}); diff --git a/exercises/051_values.zig b/exercises/051_values.zig index f2653f9..848b6a8 100644 --- a/exercises/051_values.zig +++ b/exercises/051_values.zig @@ -87,7 +87,7 @@ pub fn main() void { // Let's assign the std.debug.print function to a const named // "print" so that we can use this new name later! - const print = ???; + const print = std.debug.print; // Now let's look at assigning and pointing to values in Zig. // @@ -152,13 +152,13 @@ pub fn main() void { print("XP before:{}, ", .{glorp.experience}); // Fix 1 of 2 goes here: - levelUp(glorp, reward_xp); + levelUp(&glorp, reward_xp); print("after:{}.\n", .{glorp.experience}); } // Fix 2 of 2 goes here: -fn levelUp(character_access: Character, xp: u32) void { +fn levelUp(character_access: *Character, xp: u32) void { character_access.experience += xp; } diff --git a/exercises/052_slices.zig b/exercises/052_slices.zig index af5930b..24dbb08 100644 --- a/exercises/052_slices.zig +++ b/exercises/052_slices.zig @@ -32,8 +32,8 @@ pub fn main() void { var cards = [8]u8{ 'A', '4', 'K', '8', '5', '2', 'Q', 'J' }; // Please put the first 4 cards in hand1 and the rest in hand2. - const hand1: []u8 = cards[???]; - const hand2: []u8 = cards[???]; + const hand1: []u8 = cards[0..4]; + const hand2: []u8 = cards[4..]; std.debug.print("Hand1: ", .{}); printHand(hand1); @@ -43,7 +43,7 @@ pub fn main() void { } // Please lend this function a hand. A u8 slice hand, that is. -fn printHand(hand: ???) void { +fn printHand(hand: []u8) void { for (hand) |h| { std.debug.print("{u} ", .{h}); } diff --git a/exercises/053_slices2.zig b/exercises/053_slices2.zig index 545b4da..924f6a3 100644 --- a/exercises/053_slices2.zig +++ b/exercises/053_slices2.zig @@ -17,19 +17,19 @@ const std = @import("std"); pub fn main() void { const scrambled = "great base for all your justice are belong to us"; - const base1: []u8 = scrambled[15..23]; - const base2: []u8 = scrambled[6..10]; - const base3: []u8 = scrambled[32..]; + const base1: []const u8 = scrambled[15..23]; + const base2: []const u8 = scrambled[6..10]; + const base3: []const u8 = scrambled[32..]; printPhrase(base1, base2, base3); - const justice1: []u8 = scrambled[11..14]; - const justice2: []u8 = scrambled[0..5]; - const justice3: []u8 = scrambled[24..31]; + const justice1: []const u8 = scrambled[11..14]; + const justice2: []const u8 = scrambled[0..5]; + const justice3: []const u8 = scrambled[24..31]; printPhrase(justice1, justice2, justice3); std.debug.print("\n", .{}); } -fn printPhrase(part1: []u8, part2: []u8, part3: []u8) void { +fn printPhrase(part1: []const u8, part2: []const u8, part3: []const u8) void { std.debug.print("'{s} {s} {s}.' ", .{ part1, part2, part3 }); } diff --git a/exercises/054_manypointers.zig b/exercises/054_manypointers.zig index 695b55e..b6e39f2 100644 --- a/exercises/054_manypointers.zig +++ b/exercises/054_manypointers.zig @@ -32,7 +32,7 @@ pub fn main() void { // we can CONVERT IT TO A SLICE. (Hint: we do know the length!) // // Please fix this line so the print statement below can print it: - const zen12_string: []const u8 = zen_manyptr; + const zen12_string: []const u8 = zen_manyptr[0..21]; // Here's the moment of truth! std.debug.print("{s}\n", .{zen12_string}); diff --git a/exercises/055_unions.zig b/exercises/055_unions.zig index 6339fc8..f6913b4 100644 --- a/exercises/055_unions.zig +++ b/exercises/055_unions.zig @@ -59,8 +59,8 @@ pub fn main() void { std.debug.print("Insect report! ", .{}); // Oops! We've made a mistake here. - printInsect(ant, AntOrBee.c); - printInsect(bee, AntOrBee.c); + printInsect(ant, AntOrBee.a); + printInsect(bee, AntOrBee.b); std.debug.print("\n", .{}); } diff --git a/exercises/056_unions2.zig b/exercises/056_unions2.zig index e4294db..911ee42 100644 --- a/exercises/056_unions2.zig +++ b/exercises/056_unions2.zig @@ -44,14 +44,14 @@ pub fn main() void { std.debug.print("Insect report! ", .{}); // Could it really be as simple as just passing the union? - printInsect(???); - printInsect(???); + printInsect(ant); + printInsect(bee); std.debug.print("\n", .{}); } fn printInsect(insect: Insect) void { - switch (???) { + switch (insect) { .still_alive => |a| std.debug.print("Ant alive is: {}. ", .{a}), .flowers_visited => |f| std.debug.print("Bee visited {} flowers. ", .{f}), } diff --git a/exercises/057_unions3.zig b/exercises/057_unions3.zig index 142180f..860c979 100644 --- a/exercises/057_unions3.zig +++ b/exercises/057_unions3.zig @@ -15,7 +15,7 @@ // const std = @import("std"); -const Insect = union(InsectStat) { +const Insect = union(enum) { flowers_visited: u16, still_alive: bool, }; @@ -24,6 +24,8 @@ pub fn main() void { var ant = Insect{ .still_alive = true }; var bee = Insect{ .flowers_visited = 17 }; + //ant.flowers_visited = 26; // wow 'terminated unexpectedly' isn't super helpful error + std.debug.print("Insect report! ", .{}); printInsect(ant); diff --git a/exercises/058_quiz7.zig b/exercises/058_quiz7.zig index 0d5bcaa..02aa4d1 100644 --- a/exercises/058_quiz7.zig +++ b/exercises/058_quiz7.zig @@ -107,7 +107,7 @@ const Path = struct { const a_paths = [_]Path{ Path{ .from = &a, // from: Archer's Point - .to = &b, // to: Bridge + .to = &b, // to: Bridge .dist = 2, }, }; @@ -115,12 +115,12 @@ const a_paths = [_]Path{ const b_paths = [_]Path{ Path{ .from = &b, // from: Bridge - .to = &a, // to: Archer's Point + .to = &a, // to: Archer's Point .dist = 2, }, Path{ .from = &b, // from: Bridge - .to = &d, // to: Dogwood Grove + .to = &d, // to: Dogwood Grove .dist = 1, }, }; @@ -128,12 +128,12 @@ const b_paths = [_]Path{ const c_paths = [_]Path{ Path{ .from = &c, // from: Cottage - .to = &d, // to: Dogwood Grove + .to = &d, // to: Dogwood Grove .dist = 3, }, Path{ .from = &c, // from: Cottage - .to = &e, // to: East Pond + .to = &e, // to: East Pond .dist = 2, }, }; @@ -141,17 +141,17 @@ const c_paths = [_]Path{ const d_paths = [_]Path{ Path{ .from = &d, // from: Dogwood Grove - .to = &b, // to: Bridge + .to = &b, // to: Bridge .dist = 1, }, Path{ .from = &d, // from: Dogwood Grove - .to = &c, // to: Cottage + .to = &c, // to: Cottage .dist = 3, }, Path{ .from = &d, // from: Dogwood Grove - .to = &f, // to: Fox Pond + .to = &f, // to: Fox Pond .dist = 7, }, }; @@ -159,20 +159,20 @@ const d_paths = [_]Path{ const e_paths = [_]Path{ Path{ .from = &e, // from: East Pond - .to = &c, // to: Cottage + .to = &c, // to: Cottage .dist = 2, }, Path{ .from = &e, // from: East Pond - .to = &f, // to: Fox Pond - .dist = 1, // (one-way down a short waterfall!) + .to = &f, // to: Fox Pond + .dist = 1, // (one-way down a short waterfall!) }, }; const f_paths = [_]Path{ Path{ .from = &f, // from: Fox Pond - .to = &d, // to: Dogwood Grove + .to = &d, // to: Dogwood Grove .dist = 7, }, }; @@ -192,8 +192,8 @@ const TripItem = union(enum) { // Oops! The hermit forgot how to capture the union values // in a switch statement. Please capture both values as // 'p' so the print statements work! - .place => print("{s}", .{p.name}), - .path => print("--{}->", .{p.dist}), + .place => |p| print("{s}", .{p.name}), + .path => |p| print("--{}->", .{p.dist}), } } }; @@ -255,7 +255,7 @@ const HermitsNotebook = struct { // dereference and optional value "unwrapping" look // together. Remember that you return the address with the // "&" operator. - if (place == entry.*.?.place) return entry; + if (place == entry.*.?.place) return &entry.*.?; // Try to make your answer this long:__________; } return null; @@ -309,7 +309,7 @@ const HermitsNotebook = struct { // // Looks like the hermit forgot something in the return value of // this function. What could that be? - fn getTripTo(self: *HermitsNotebook, trip: []?TripItem, dest: *Place) void { + fn getTripTo(self: *HermitsNotebook, trip: []?TripItem, dest: *Place) TripError!void { // We start at the destination entry. const destination_entry = self.getEntry(dest); @@ -355,8 +355,8 @@ pub fn main() void { // Here's where the hermit decides where he would like to go. Once // you get the program working, try some different Places on the // map! - const start = &a; // Archer's Point - const destination = &f; // Fox Pond + const start = &a; // Archer's Point + const destination = &f; // Fox Pond // Store each Path array as a slice in each Place. As mentioned // above, we needed to delay making these references to avoid diff --git a/exercises/059_integers.zig b/exercises/059_integers.zig index 5a6295d..dc94815 100644 --- a/exercises/059_integers.zig +++ b/exercises/059_integers.zig @@ -18,10 +18,13 @@ const print = @import("std").debug.print; pub fn main() void { - var zig = [_]u8 { - 0o131, // octal - 0b1101000, // binary - 0x66, // hex + var zig = [_]u8{ + 0o132, // octal + 0b1101001, // binary + 0x67, // hex + // 'Z', + // 'i', + // 'g', }; print("{s} is cool.\n", .{zig}); diff --git a/exercises/060_floats.zig b/exercises/060_floats.zig index a223257..beac853 100644 --- a/exercises/060_floats.zig +++ b/exercises/060_floats.zig @@ -40,7 +40,7 @@ pub fn main() void { // // We'll convert this weight from tons to kilograms at a // conversion of 907.18kg to the ton. - var shuttle_weight: f16 = 907.18 * 2200; + var shuttle_weight: f32 = 907.18 * 2200.0; // By default, float values are formatted in scientific // notation. Try experimenting with '{d}' and '{d:.3}' to see |