Created
August 2, 2012 14:34
-
-
Save boronology/3237498 to your computer and use it in GitHub Desktop.
FizzBuzz
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> | |
| #include <string> | |
| std::string fizzbuzz = "FizzBuzz"; | |
| std::string fizz = "Fizz"; | |
| std::string buzz = "Buzz"; | |
| struct dummyint | |
| { | |
| dummyint(const int i); | |
| int val; | |
| } | |
| ; | |
| dummyint::dummyint(const int i) | |
| :val(i) | |
| { | |
| } | |
| std::ostream& operator<<(std::ostream& os,dummyint i) | |
| { | |
| if(!(i.val%15)) | |
| { | |
| return os << fizzbuzz; | |
| } | |
| else if(!(i.val%5)) | |
| { | |
| return os << buzz; | |
| } | |
| else if(!(i.val%3)) | |
| { | |
| return os << fizz; | |
| } | |
| else | |
| { | |
| return os << i.val; | |
| } | |
| } | |
| int main(int argc, char *argv[]) | |
| { | |
| for(int i=0;i<100;i++) | |
| { | |
| std::cout << dummyint(i) << std::endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment