The FizzBuzz Game
by CodeChum Admin
Let's play a game of FizzBuzz! It works just like the popular childhood game "PopCorn", but with rules of math applied since math is fun, right? Just print out "Fizz" when the given number is divisible by 3, "Buzz" when it's divisible by 5, and "FizzBuzz" when it's divisible by both 3 and 5!
Let the game begin!
Input
A line containing an integer.
15
Output
A line containing a string.
FizzBuzz
#include <iostream>
using namespace std;
int main(){
int number;
cout << "Enter integer number: ";
cin >> number;
if (number%3==0) {
cout << "Fizz";
}
if (number % 5 == 0) {
cout << "Buzz";
}
else {
cout << "Number isn't divisible by 3 or 5.";
}
return 0;
}
Comments
Leave a comment