mirror of
https://git.aramjonghu.dev/AramJonghu/ziglings.git
synced 2026-09-01 08:03:29 +02:00
progress
This commit is contained in:
@@ -14,7 +14,7 @@ pub fn main(init: std.process.Init) !void {
|
||||
var stdout_writer = std.Io.File.stdout().writer(io, &.{});
|
||||
const stdout = &stdout_writer.interface;
|
||||
|
||||
const my_num: u32 = getNumber();
|
||||
const my_num: u32 = try getNumber();
|
||||
|
||||
try stdout.print("my_num={}\n", .{my_num});
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
const std = @import("std");
|
||||
|
||||
// Please complete the enum!
|
||||
const Ops = enum { ??? };
|
||||
const Ops = enum { inc, dec, pow };
|
||||
|
||||
pub fn main() void {
|
||||
const operations = [_]Ops{
|
||||
|
||||
@@ -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>
|
||||
\\
|
||||
, .{
|
||||
@intFromEnum(Color.red),
|
||||
@intFromEnum(Color.green),
|
||||
@intFromEnum(???), // Oops! We're missing something!
|
||||
@intFromEnum(Color.blue), // Oops! We're missing something!
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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", .{
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
|
||||
@@ -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.* });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user