Fizzbuzz project is bugged, I think

When I save, the wheel keeps spinning and nothing happens. Terminal shows nothing

#include <iostream>

int main() {
  // Brain explodes here
  for (int x = 1; 101; x++)
  {
    if (x % 3 == 0)
    {
      x = "Fizz";
    }
    else if (x % 5 == 0)
    {
      x = "Buzz";
    }
    else if (x % 5 == 0 && x % 3 == 0)
    {
      x = "FizzBuzz";
    }
    std::cout << x;
    
  }   
  
}

Well for starters, you are creating an infinite loop here, there is no stop condition, meaning this for loop will run virtually forever.

The correct format for a for loop is as follows:

for (startValue; stopCondition; changeValue)

For example:

for the start value of i = 0, while i is smaller than or equal to 100, execute the code then add 1 to i, then repeat this check.

for (int i = 0; i <= 100; i++) {
    // The Code to be executed
}
3 Likes

Why didn’t your reply show up in my notifications?

Anyway, thanks, the answer seems obvious now. Can’t believe I missed that.