Skip to content

Instantly share code, notes, and snippets.

@Angel-Rojas
Last active September 10, 2015 05:58
Show Gist options
  • Save Angel-Rojas/2445402dfb3884fd2b34 to your computer and use it in GitHub Desktop.
Save Angel-Rojas/2445402dfb3884fd2b34 to your computer and use it in GitHub Desktop.
A small but fun way of writing the '99 bottles of beer' song, with "clear" function.
/*
* This script is about the 99 Bottles of Beer on the wall song.
*
* Author: Angel Rojas
* Created on: Sept 09, 2015
* Source file: BeerSong.cpp
*/
#include <iostream>
#include <windows.h> // allows us to 'Delay' our output using milliseconds!
using namespace std;
// !Warning! this script might run into issues if not using Windows, or even
// if you are using windows. The 'system()' command might not always work.
int main() {
for (int numMain=99; numMain >= 1; --numMain) //we set up our 99 lines of Beer
{
int lower = numMain - 1; // 'lower' will be the next # of beers after the initial count.
if (numMain == 1) {
cout << numMain << " Last bottle of booze on the wall, " << numMain <<
" last bottle of booze!" << endl;
cout << " You take one down, you pass it around. " << endl;
cout << lower << " bottles of booze on the wall!" << endl;
}
else if (numMain == 2) //checking to see if 'lower' will equal 1. Grammar Issues!
{
cout << numMain << " Bottles of booze on the wall, " << numMain <<
" bottles of booze!" << endl;
cout << " You take one down, you pass it around. " << endl;
cout << lower << " last bottle of booze on the wall!" << endl;
}
else
{
cout << numMain << " Bottles of booze on the wall, " << numMain <<
" bottles of booze!" << endl;
cout << " You take one down, you pass it around. " << endl;
cout << lower << " bottles of booze on the wall!" << endl;
}
Sleep( 5500 ); // 'Sleep' is a time delay, and the # reads as milliseconds.
system("CLS");
}
return 0;
}
@Angel-Rojas
Copy link
Author

Output: Will show the number of beers counting down, while 'refreshing' the screen in order to not spam the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment