aboutsummaryrefslogtreecommitdiff
path: root/38_structs2.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-02-09 18:36:57 -0500
committerDave Gauer <dave@ratfactor.com>2021-02-09 18:36:57 -0500
commit55ad7c32f2d534b1fbd438204d21738f958c51a5 (patch)
tree16be4b53193105a759b3eec25be5e664d41c428d /38_structs2.zig
parentcf0920de31e9b5f3c5ba6de19a1b4c8d0c58b907 (diff)
downloadziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.tar.gz
ziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.tar.bz2
ziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.tar.xz
ziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.zip
Moved exercises to exercises because exercises
Diffstat (limited to '38_structs2.zig')
-rw-r--r--38_structs2.zig51
1 files changed, 0 insertions, 51 deletions
diff --git a/38_structs2.zig b/38_structs2.zig
deleted file mode 100644
index b6def93..0000000
--- a/38_structs2.zig
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-// Grouping values in structs is not merely convenient. It also allows
-// us to treat the values as a single item when storing them, passing
-// them to functions, etc.
-//
-// This exercise demonstrates how we can store structs in an array and
-// how doing so lets us print them all (both) using a loop.
-//
-const std = @import("std");
-
-const Class = enum{
- wizard,
- thief,
- bard,
- warrior,
-};
-
-const Character = struct{
- class: Class,
- gold: u32,
- health: u8,
- experience: u32,
-};
-
-pub fn main() void {
- var chars: [2]Character = undefined;
-
- // Glorp the Wise
- chars[0] = Character{
- .class = Class.wizard,
- .gold = 20,
- .health = 100,
- .experience = 10,
- };
-
- // Please add "Zump the Loud" with the following properties:
- //
- // class bard
- // gold 10
- // health 100
- // experience 20
- //
- // Feel free to run this program without adding Zump. What does
- // it do and why?
-
- // Printing all RPG characters in a loop:
- for (chars) |c, num| {
- std.debug.print("Character {} - G:{} H:{} XP:{}\n",
- .{num+1, c.gold, c.health, c.experience});
- }
-}