fbpx

C++: 99 Bottles of Beer

Bjarne-stroustrup
 

The beersong

In this puzzle, write code to print out the entire “99 bottles of beer on the wall” song.

For those who do not know the song, the lyrics follow this form:

X bottles of beer on the wall
X bottles of beer
Take one down, pass it around
X-1 bottles of beer on the wall

X-1 bottles of beer on the wall
...
Take one down, pass it around
0 bottles of beer on the wall

Where X and X-1 are replaced by numbers of course. Grammatical support for “1 bottle of beer” is optional. As with any puzzle, try to do it in as creative/concise/comical a way as possible (simple, obvious solutions allowed, too).

#include <iostream>
using std::cout;

int main() 
{
	for(int bottles(99); bottles > 0; bottles -= 1){
		cout << bottles << " bottles of beer on the wall\n"
		<< bottles << " bottles of beer\n"
		<< "Take one down, pass it around\n"
		<< bottles - 1 << " bottles of beer on the wall\n\n";
	}
}

SOURCE

Content is available under GNU Free Documentation License 1.2.

Our team found a curious site for our readers that are fans of online gaming, a rather exciting site that provides the latest gaming technology. Casinodots.com is the site, they compile the best reviews of MGA casino utan svensk licens sites. This site might pique your curiosity and you can win extra money!