Skip to content

Instantly share code, notes, and snippets.

@zohaad
Last active July 26, 2016 17:06
Show Gist options
  • Save zohaad/8b1287e88997ace52a4139d1ed838662 to your computer and use it in GitHub Desktop.
Save zohaad/8b1287e88997ace52a4139d1ed838662 to your computer and use it in GitHub Desktop.
#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);
}
#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