221V 3 дней назад
Родитель
Сommit
9e6ded254f
1 измененных файлов с 31 добавлено и 30 удалено
  1. 31 30
      exercises/035_enums.zig

+ 31 - 30
exercises/035_enums.zig

@@ -20,36 +20,37 @@
 const std = @import("std");
 
 // Please complete the enum!
-const Ops = enum { ??? };
+const Ops = enum { inc, pow, dec };
 
-pub fn main() void {
-    const operations = [_]Ops{
-        Ops.inc,
-        Ops.inc,
-        Ops.inc,
-        Ops.pow,
-        Ops.dec,
-        Ops.dec,
-    };
-
-    var current_value: u32 = 0;
-
-    for (operations) |op| {
-        switch (op) {
-            Ops.inc => {
-                current_value += 1;
-            },
-            Ops.dec => {
-                current_value -= 1;
-            },
-            Ops.pow => {
-                current_value *= current_value;
-            },
-            // No "else" needed! Why is that?
-        }
-
-        std.debug.print("{} ", .{current_value});
+pub fn main() void{
+  const operations = [_]Ops{
+    Ops.inc,
+    Ops.inc,
+    Ops.inc,
+    Ops.pow,
+    Ops.dec,
+    Ops.dec,
+  };
+  
+  var current_value: u32 = 0;
+  
+  for(operations) |op|{
+    switch(op){
+      Ops.inc => {
+        current_value += 1;
+      },
+      Ops.dec => {
+        current_value -= 1;
+      },
+      Ops.pow => {
+        current_value *= current_value;
+      },
+      // No "else" needed! Why is that?
     }
-
-    std.debug.print("\n", .{});
+    
+    std.debug.print("{} ", .{current_value});
+  }
+  
+  std.debug.print("\n", .{});
 }
+