Does this count?

Hi everyone, I am very new to programming. Below is my attempt at solving the cliche “FizzBuzz” problem. It seems that I solved it correctly (as in the outputted code works) but I’m not sure this is the correct way/most efficient way of solving it, since I changed the first character out line to remove the integer i, instead just creating a new line with /n and defining what to do with the integer at the end statement.

#include

int main() {

for (int i = 1; i <= 100; i++) {

std::cout << "\n";

if (i % 15 == 0) {

std::cout << "FizzBuzz";


      }
else if (i % 5 == 0) {
   std::cout << "Buzz";

  }
else if (i % 3 == 0) {

  std::cout << "Fizz";
}

else {

  std::cout << i;
}

  }

}

Thank you all very much.

1 Like

seems good to me.
(I don’t think it matters where in the loop the std::cout << "\n"; is.)

1 Like