SeanMcCammon C# .Net core 3 Software Developer

FizzBuzz In C++

FizzBuzz In C++

Recently I started looking for a new role, a new developer role. During my interviews, I have come across a number of questions and coding challenges. For each of these challenges, I take my time, create the code. I then come home and revisit that challenge to write a better solution.

Recently I started looking for a new role, a new developer role. During my interviews, I have come across a number of questions and coding challenges. For each of these challenges, I take my time, create the code. I then come home and revisit that challenge to write a better solution.

In this new solution I create it in a few different languages, just to challenge myself, but to also provide my solution to anyone who maybe looking for the solution the this quiz question.

For this challenge I take one of the common coding quizzes I've seen asked during an interview is the FizzBuzz code question.

FizzBuzz

What is FizzBuzz? Simply put, its a challenge that will print one of 3 words when a number is divisible by a given number, and if not divisible it will output the number.

So, it seems common to give the following parameters:

  1. Number range is 1 to 100
  2. If the number is divisible by 3 then output Fizz
  3. If the number is divisible by 5 then output Buzz
  4. If the number is divisible by 3 and 5 then output Fizzbuzz
  5. If the number is not divisible by the above values, output the value

FizzBuzz in C++

Given the above parameters, here is my solution for this FizzBuzz challenge written in C++

#include <iostream>

int main()
{
	bool found = false;

	for(int counter=1; counter <= 100; counter++)
	{
		if (counter%3 == 0) {
			std::cout << "Fizz"; 
			found = true;
		}

		if (counter%5 == 0)
		{
			std::cout << "Buzz";
			found = true;
		}

		if (!found)
			std::cout << counter;

		std::cout << std::endl;
		found = false;
	}
}

Solution On YouTube

I've also created a video of me going through my solution on YouTube is you wanted to get more insight into my solution. Check out the video linked below

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram