-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fizzbuzz.cpp for clean code apendix
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
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
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
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;}} |
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
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".*/ |