Remember the game of FizzBuzz from the last time? Well, I thought of some changes in the game, and also with the help of loops as well. Firstly, you'll be asking for a random integer and then loop from 1 until that integer. Then, implement these conditions in the game:
#include <iostream>
using namespace std;
void fizzBuzz(int n){
if(!(n%3)){
cout<<"Fizz";
}
if(!(n%5)){
cout<<"Buzz";
}
else if(n%3 && n%5){
cout<<n;
}
cout<<endl;
}
int main(){
int n;
cout<<"Input the integer: ";
cin>>n;
for(int i = 1; i <= n; i++){
fizzBuzz(i);
}
return 0;
}
Comments
Leave a comment