Skip to content

Commit 1c8a7ab

Browse files
authored
Merge pull request IIdroyII#23 from Bwc9876/fizz-buzz
Implement Fizz Buzz in C++
2 parents 558d524 + be31e54 commit 1c8a7ab

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

fizz_buzz.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main() {
6+
7+
// Begin our main loop of 1-50
8+
for (int i = 1; i <= 50; i++) {
9+
10+
string output = "";
11+
12+
if (i % 3 == 0) output += "Fizz"; // If our current number is a multiple of 3, add "Fizz to the output"
13+
if (i % 5 == 0) output += "Buzz"; // If our current number is a multiple of 5, add "Buzz to the output"
14+
15+
if (output == "") output = to_string(i); // If the output is empty (our number isn't a multiple of 3 or 5), we simply set it to our number
16+
17+
cout << output << endl; // Show the user the output
18+
19+
}
20+
21+
}

0 commit comments

Comments
 (0)