FAQ: Loops - 99 Bottles

This is aggravating!!! I have the “99 Bottles” exercise work perfectly but it won’t let me continue. The “Next” button is shaded out. How do I move forward to the next step? Thanks in advance for any help.

So I am pretty new to coding in general and after reading the thread and seeing the correct code I understand the correct answer but wondering if the below code would also be correct. This was my first attempt at the exercise and it passed. Any ideas on the flaws this code has? Thanks (both - do not show up but I do have them as well as iostream which is also hidden below)

#include <iostream>

int main() {
  
  for (int b = 99; b > 0; b--) {
    std::cout << b << " bottles of pop on the wall.\nTake one down and pass it around.\n";
  }

If it passed, I suppose it’s fine. I don’t see anything syntactically or logically wrong with it. It doesn’t produce the same output stanzas of the song that the example in the instructions shows, but if it passed, and you’re happy with it, I wouldn’t worry about it. To make your code in forum posts retain it’s original formatting and special characters (like it does after I edited your post) see How do I format code in my posts?

1 Like

I have got the code right, but the guide is not accepting it. I know it because in the terminal it worked ?
Also it happened for many of my codes.

This exercise is still broken. Shouldn’t require user’s to find away around a broken exercise. Please don’t give me a spiel about how programmers need the problem solving abilities to fix issues just like this.

What is broken? I know the exercise is picky about your output exactly matching the expected output. Forum moderators don’t work for Codecademy, and can’t edit lessons or exercises, but if you can explain how it is broken, I may be able to draw attention to the exercise from someone who can fix it.

Hey, is there any reason why the website wouldn’t accept my code? It output correctly so far as I could tell, so I’m not sure why it wouldn’t let it go through

int main() { // Write a for loop here: for(int i = 99; i > 0; i--){ std::cout<<i<<" bottles of pop on the wall\nTake one down and pass it around.\n"<<i-1<<" bottles of pop on the wall.\n\n"; } }

so curious why won’t my code work?
int i > 0
int i = 99
for ( i-- )
{std::cout << i << " bottles of pop on the wall.\n";
std::cout<< “Take one down and pass it around.\n”;
i-- “bottles of pop on the wall.\n”;
}

I’m not sure if it’s a copy/paste issue but at present that doesn’t look like valid syntax (broken declaration, missing semicolons, incomplete for loop expression). Double check all your syntax. If you’re posting code to the forums please see How do I format code in my posts? too as it makes it much easier for others to read.

#include

int main() {

// Write a for loop here:

for (int i = 99; i > 0; i–) {

std::cout << i << " bottles of pop on the wall. " << i << " bottles of pop. You take one down and pass it around. " << i - 1 << " bottles of pop on the wall\n\n";

}

}

I did not understand this assignment at all, but i have understood the official solution which is:
#include

int main() {

// Write a for loop here:

for (int i = 99; i > 0; i–) {

std::cout << i << " bottles of pop on the wall.\n";

std::cout << "Take one down and pass it around.\n";

std::cout << i - 1 << " bottles of pop on the wall.\n\n";

}

std::cout << “No more bottles of pop on the wall.\n”;

std::cout << “No more bottles of pop.\n”;

std::cout << “Go to the store and buy some more,\n”;

std::cout << “99 bottles of pop on the wall.\n”;

}

Thanks everyone!

1 Like

Same problem, I had a solution that worked perfectly fine in practice and for some reason it didn’t qualify. This probably should be revamped.

Works perfectly, except at 2 bottles of beer I get 1 bottles of beer displayed. But no good. I know a lot of others here are having the same issue. Not sure why this isn’t fixed after literal years.

#include

int main() {

// Write a for loop here:
for (int i = 99; i > 0; i–)
{
if (i == 1)
{
std::cout << “1 Bottle of beer on the wall, one bottle of beer.\n”;
std::cout << “Take one down, pass it around. No bottles of beer on the wall.\n”;
}
else
{
std::cout << i << " bottles of beer on the wall, " << i << " bottles of beer.\n";
std::cout << “Take one down, pass it around. " << i-1 << " bottles of beer on the wall.\n”;
}
}

}

I am brand new to coding, like have never seen it before last week, and I have made the program run two different ways. I don’t know why its not working.

If anyone is having trouble, this one made it work for me (just remember to change the quote marks, and to include the iostream

cool :sunglasses: yes codecademy I want to comment not to like :sunglasses:

does it run? You may also share your code :smiley:

You forget to put ; at the end of int i > 0 also it should be int i = 0; and the same with int i = 99
then in the for loop you have to type ; eg for(;;i–) and you should type std::cout << i -1 <<“bottles . … .” you forget the std::cout << part and i-- decrement the value of i that is a logical error it only should decrement in the for brackets hope it help :wink:

for (int i = 99; i > 0; i--) {
    std::cout << i << " bottles pf pop on the wall.\n";
    std::cout << "Take one down and pass it around.\n";
    std::cout << "\n";
  }

My code is giving me the right result but it is saying it is wrong? What is wrong?

// You wrote:
std::cout << i << " bottles pf pop on the wall.\n";

// It should be:
std::cout << i << " bottles of pop on the wall.\n";

Also, your output:

99 bottles pf pop on the wall.
Take one down and pass it around.

98 bottles pf pop on the wall.
Take one down and pass it around.
...

Expected output:

99 bottles of pop on the wall.
Take one down and pass it around.
98 bottles of pop on the wall.

98 bottles of pop on the wall.
Take one down and pass it around.
97 bottles of pop on the wall
...