Skip to content

Commit

Permalink
Added fizzbuzz.cpp for clean code apendix
Browse files Browse the repository at this point in the history
Added file fizzbuzz.cpp for the clean code appendix, purposefully written without clean code conventions. Additionally added fizzbuzz_pretty.cpp; Same program, but with indents, code conventions, comments etc.
  • Loading branch information
nick75g committed Nov 23, 2024
1 parent ee3f40a commit b17c7df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions appendix/fizzbuzz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <string>
#include <iostream>
int main() {std::string a="";
for(int i=1;i<=100;i++){a="";if(i%3==0){a+="Fizz";}
if(i%5==0){a+="Buzz";}if(a==""){a=std::to_string(i);}
std::cout<<a<<std::endl;}}
23 changes: 23 additions & 0 deletions appendix/fizzbuzz_pretty.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <string>
#include <iostream>
int main() {
std::string output = ""; //Wir kreieren eine Variable für den Output
for(int i = 1; i <= 100; i++){ //Für alle Zahlen von 1 bis 100:
output = "";
if(i % 3 == 0){
output += "Fizz"; //Falls die Zahl durch 3 Teilbar ist, fügen wir dem Output "Fizz" hinzu
}
if(i % 5 == 0){
output += "Buzz"; //Falls die Zahl durch 5 Teilbar ist, fügen wir dem Output "Buzz" hinzu
}
if(output == ""){
output = std::to_string(i); //Falls der Output danach immer noch leer ist, wird die Zahl zum Output
}
std::cout << output << std::endl; //Wir geben den Output aus
}
}

/*Sprich: Dieses Programm spielt das englische Kinderspiel "FizzBuzz"; Man sagt nacheinander jede Zahl, aber
- wenn die Zahl durch 3 teilbar ist (3, 6,...), sagt man "Fizz"
- wenn die Zahl durch 5 teilbar ist (5, 10,...), sagt man "Buzz"
- Wenn die Zahl durch beides teilbar ist (15, 30,...), sagt man "FizzBuzz".*/

0 comments on commit b17c7df

Please sign in to comment.