Skip to content

Instantly share code, notes, and snippets.

@TheBuzzSaw
Created April 10, 2015 18:09
Show Gist options
  • Select an option

  • Save TheBuzzSaw/5acda39a77343ce45fb3 to your computer and use it in GitHub Desktop.

Select an option

Save TheBuzzSaw/5acda39a77343ce45fb3 to your computer and use it in GitHub Desktop.
FizzBuzz solution that allows new multiples/words!
#include <iostream>
using namespace std;
struct Word
{
int n;
const char* text;
};
int main(int argc, char** argv)
{
Word words[] = {
{3, "Fizz"},
{5, "Buzz"},
{0, nullptr}
};
for (int i = 1; i <= 100; ++i)
{
bool wroteWord = false;
for (auto j = words; j->n > 1 && j->text != nullptr; ++j)
{
if (!(i % j->n))
{
cout << j->text;
wroteWord = true;
}
}
if (!wroteWord) cout << i;
cout << '\n';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment