Last active
July 26, 2016 17:06
-
-
Save zohaad/8b1287e88997ace52a4139d1ed838662 to your computer and use it in GitHub Desktop.
This file contains 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> | |
using namespace std; | |
// just to prove I'm not a noob, version 2 | |
// the right way | |
void fizzbuzz(int num){ | |
for(int x = 1; x <= num; x++) { | |
string y = ""; | |
if(x % 3 == 0) { | |
y += "Fizz"; | |
} | |
if(x % 5 == 0) { | |
y += "Buzz"; | |
} | |
//check if x was fizzbuzzed | |
if(y != "") { | |
cout << y << endl; | |
} | |
else{ | |
cout << x << endl; | |
} | |
} | |
} | |
int main(){ | |
fizzbuzz(100); | |
} |
This file contains 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> | |
using namespace std; | |
// This is the old file, improvements are in fizzbuzz.cpp | |
void fizzbuzz(int fbCount){ | |
for(int x = 1; x <= fbCount; x++) { | |
if(x % 3 == 0 && x % 5 == 0) { | |
string y = "FizzBuzz"; | |
cout << y; | |
} | |
else if(x % 3 == 0 && !(x % 5 == 0) ) { | |
string y = "Fizz"; | |
cout << y; | |
} | |
else if (!(x % 3 == 0) && x % 5 == 0) { | |
string y = "Buzz"; | |
cout << y; | |
} | |
else{ | |
cout << x; | |
} | |
cout << endl; | |
} | |
} | |
int main(){ | |
fizzbuzz(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment