mirror of
https://codeberg.org/ziglings/exercises.git
synced 2026-06-09 08:30:00 +00:00
Normalized exercise output, answers (#41)
1. All exercises should print a trailing \n 2. The build script should always show you _exactly_ what it's looking for when you get it wrong. Therefore, .output should be set to the exact expected output.
This commit is contained in:
@@ -25,5 +25,5 @@ pub fn main() void {
|
||||
// an error. Can you set the type correctly above?
|
||||
my_number = MyNumberError.TooSmall;
|
||||
|
||||
std.debug.print("I compiled!", .{});
|
||||
std.debug.print("I compiled!\n", .{});
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ pub fn main() void {
|
||||
var a: u32 = addTwenty(44) catch 22;
|
||||
var b: u32 = addTwenty(4) ??? 22;
|
||||
|
||||
std.debug.print("a={}, b={}", .{ a, b });
|
||||
std.debug.print("a={}, b={}\n", .{ a, b });
|
||||
}
|
||||
|
||||
// Please provide the return type from this function.
|
||||
|
||||
@@ -25,7 +25,7 @@ pub fn main() void {
|
||||
var b: u32 = makeJustRight(14) catch 0;
|
||||
var c: u32 = makeJustRight(4) catch 0;
|
||||
|
||||
std.debug.print("a={}, b={}, c={}", .{ a, b, c });
|
||||
std.debug.print("a={}, b={}, c={}\n", .{ a, b, c });
|
||||
}
|
||||
|
||||
// In this silly example we've split the responsibility of making
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn main() void {
|
||||
var b: u32 = addFive(14) catch 0;
|
||||
var c: u32 = addFive(4) catch 0;
|
||||
|
||||
std.debug.print("a={}, b={}, c={}", .{ a, b, c });
|
||||
std.debug.print("a={}, b={}, c={}\n", .{ a, b, c });
|
||||
}
|
||||
|
||||
fn addFive(n: u32) MyNumberError!u32 {
|
||||
|
||||
@@ -53,6 +53,7 @@ pub fn main() void {
|
||||
\\ <span style="color: #{x:0>6}">Green</span>
|
||||
\\ <span style="color: #{}">Blue</span>
|
||||
\\</p>
|
||||
\\
|
||||
, .{
|
||||
@enumToInt(Color.red),
|
||||
@enumToInt(Color.green),
|
||||
|
||||
@@ -52,7 +52,7 @@ pub fn main() void {
|
||||
// Ouch! Glorp takes a punch!
|
||||
glorp_the_wise.health -= 10;
|
||||
|
||||
std.debug.print("Your wizard has {} health and {} gold.", .{
|
||||
std.debug.print("Your wizard has {} health and {} gold.\n", .{
|
||||
glorp_the_wise.health,
|
||||
glorp_the_wise.gold,
|
||||
});
|
||||
|
||||
@@ -73,7 +73,7 @@ fn printCharacter(c: *Character) void {
|
||||
.warrior => "Warrior",
|
||||
};
|
||||
|
||||
std.debug.print("{s} (G:{} H:{} XP:{})", .{
|
||||
std.debug.print("{s} (G:{} H:{} XP:{})\n", .{
|
||||
class_name,
|
||||
c.gold,
|
||||
c.health,
|
||||
|
||||
Reference in New Issue
Block a user