Created
April 10, 2015 18:09
-
-
Save TheBuzzSaw/5acda39a77343ce45fb3 to your computer and use it in GitHub Desktop.
FizzBuzz solution that allows new multiples/words!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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