From be31e545c7ba3e40a087f51f4a9e79c67618432d Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 6 Oct 2021 19:52:34 -0700 Subject: [PATCH] Implement Fizz Buzz in C++ --- fizz_buzz.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 fizz_buzz.cpp diff --git a/fizz_buzz.cpp b/fizz_buzz.cpp new file mode 100644 index 0000000..6c5fbde --- /dev/null +++ b/fizz_buzz.cpp @@ -0,0 +1,21 @@ +#include + +using namespace std; + +int main() { + + // Begin our main loop of 1-50 + for (int i = 1; i <= 50; i++) { + + string output = ""; + + if (i % 3 == 0) output += "Fizz"; // If our current number is a multiple of 3, add "Fizz to the output" + if (i % 5 == 0) output += "Buzz"; // If our current number is a multiple of 5, add "Buzz to the output" + + if (output == "") output = to_string(i); // If the output is empty (our number isn't a multiple of 3 or 5), we simply set it to our number + + cout << output << endl; // Show the user the output + + } + +}