FIZZ BUZZ need help please!

I typed this code.

####################
int main(){

}

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

std::cout << i << “\n”;

}

####################

fizzbuzz.cpp:5:1: error: expected unqualified-id before ‘for’
for (int i = 1; 1 <= 100; i++) {
^~~
fizzbuzz.cpp:5:17: error: expected unqualified-id before numeric constant
for (int i = 1; 1 <= 100; i++) {
^
fizzbuzz.cpp:5:27: error: ‘i’ does not name a type
for (int i = 1; 1 <= 100; i++) {
^
####################

I dont understand what I did wrong. I copied exactly what the tasks asked me to do.
Please help me.
Also why is it not showing me the numbers 1 through 100 on the terminal?

To preserve code formatting in forum posts, see: How do I format code in my posts?

Your code is supposed to go in between the curly braces of main,

int main() {

    for (int i = 1; i <= 100; i++) {
        std::cout << i << "\n";
    }

}

Also,

// You wrote: (This is an infinite loop because 1 will always be less than 100)
for (int i = 1; 1 <= 100; i++)
// It should be: (Loop will terminate if i exceeds 100)
for (int i = 1; i <= 100; i++)

Thanks for the response it helped a lot.

From,
Eric ADLC

1 Like