diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-01-18 20:18:49 -0500 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-01-18 20:18:49 -0500 |
commit | 879593784755f24f4a5222d7cd9a77ce5bc2c11d (patch) | |
tree | a5d796182eb08a2c60ca7d15e17075ec50c396cb | |
parent | 7e123933b915f886da8a7bba1690588a8a04ac93 (diff) | |
download | ziglings-879593784755f24f4a5222d7cd9a77ce5bc2c11d.tar.gz ziglings-879593784755f24f4a5222d7cd9a77ce5bc2c11d.tar.bz2 ziglings-879593784755f24f4a5222d7cd9a77ce5bc2c11d.tar.xz ziglings-879593784755f24f4a5222d7cd9a77ce5bc2c11d.zip |
added quiz 2
-rw-r--r-- | 13_while3.zig | 2 | ||||
-rw-r--r-- | 17_quiz2.zig | 28 | ||||
-rwxr-xr-x | ziglings | 1 |
3 files changed, 31 insertions, 0 deletions
diff --git a/13_while3.zig b/13_while3.zig index adb74ef..55fcc0a 100644 --- a/13_while3.zig +++ b/13_while3.zig @@ -21,6 +21,8 @@ pub fn main() void { // I want to print every number between 1 and 20 that is NOT // divisible by 3 or 5. while (n <= 20) : (n+=1) { + // The '%' symbol is the "modulo" operator and it + // returns the remainder after division. if(n % 3 == 0) ???; if(n % 5 == 0) ???; std.debug.print("{} ", .{n}); diff --git a/17_quiz2.zig b/17_quiz2.zig new file mode 100644 index 0000000..339f733 --- /dev/null +++ b/17_quiz2.zig @@ -0,0 +1,28 @@ +// +// Quiz time again! Let's see if you can solve the famous "Fizz Buzz"! +// +// "Players take turns to count incrementally, replacing +// any number divisible by three with the word "fizz", +// and any number divisible by five with the word "buzz". +// - From https://en.wikipedia.org/wiki/Fizz_buzz +// +// Let's go from 1 to 16. This has been started for you, but there's +// some problems. :-( +// +const std = import standard library; + +function main() void { + var i: u8 = 1; + var stop_at: u8 = 16; + + // What kind of loop is this? A 'for' or a 'while'? + ??? (i <= stop_at) : (i += 1) { + if (i % 3 == 0) std.debug.print("Fizz", .{}); + if (i % 5 == 0) std.debug.print("Buzz", .{}); + if ( !(i % 3 == 0) and !(i % 5 == 0) ) { + std.debug.print("{}", .{???}); + } + std.debug.print(", ", .{}); + } + std.debug.print("\n",.{}); +} @@ -85,6 +85,7 @@ check_it 13_while3.zig "1 2 4 7 8 11 13 14 16 17 19" check_it 14_while4.zig "n=4" check_it 15_for.zig "A Dramatic Story: :-) :-) :-( :-| :-) The End." check_it 16_for2.zig "13" +check_it 17_quiz2.zig "8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16" "This is a famous game!" echo echo " __ __ _ " |