Hello. I was just doing the first question of Chapter 5 in Jumping in C++. I completed it but I was just wondering if it was the most effeicent was to do it. And if not, what is it?
The question was: Write a program that prints out the entire lyrics to a full rendition of "99 Bottles of Bear on the Wall".
This was my program I wrote:
Code:
#include <iostream>
#include <string>
usingnamespacestd;
int main()
{
int j=98;
for(int i=99;i>2;i--)
{
cout<<i<<" bottles of beer on the wall, "<<i<<" bottles of beer.\n Take one down pass it around, "<<j<<" bottles of beer on the wall.\n";
cout<<"\n";
j--;
}
for(int i=2;i>1;i--)
{
cout<<i<<" bottles of beer on the wall, "<<i<<" bottles of beer.\n Take one down pass it around, "<<j<<" bottle of beer on the wall.\n";
cout<<"\n";
}
cout<<"1 bottle of beer on the wall, 1 bottles of beer.\n Take one down pass it around, no more bottle of beer on the wall.\n";
cout<<"\n";
cout<<"No more bottles of beer on the wall, No more bottles of beer.\n Go to the store but some more, 99 bottle of beer on the wall.\n";
}