Language C++
(hacking style)
| Date: | 04/20/05 |
| Author: | Tim Robinson |
| URL: | n/a |
| Comments: | 14 |
| Info: | n/a |
| Score: |
// C++ version of 99 Bottles of beer
// programmer: Tim Robinson timtroyr@ionet.net
// Corrections by Johannes Tevessen
#include <iostream>
using namespace std;
int main()
{
int bottles = 99;
while ( bottles > 0 )
{
cout << bottles << " bottle(s) of beer on the wall," << endl;
cout << bottles << " bottle(s) of beer." << endl;
cout << "Take one down, pass it around," << endl;
cout << --bottles << " bottle(s) of beer on the wall." << endl;
}
return 0;
}
Download Source | Write Comment
Alternative Versions
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| extreme template metaprogramming | Richard Wolf | 04/20/05 | 5 | |
| Preprocessor & self-include recursion | Chocapic | 02/27/07 | 6 | |
| feature creep | Jono | 04/27/09 | 1 | |
| meta programming | Arion Lei | 04/20/05 | 5 | |
| object-oriented version | Tim Robinson | 04/20/05 | 4 | |
| 6 | Jono | 04/15/09 | 0 | |
| ob fuscated | Tapi (Paddy O'Brien) | 08/11/05 | 4 | |
| GUI version | Martyn Davies | 05/28/05 | 1 | |
| most extreme template metaprogramming | Henrik Theiling | 12/04/11 | 0 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
system ("pause"
one line before the return to make it wait for a keyboard button press.
it's easy!
#include <iostream>
#include <windows.h>
using namespace std;
int a=99;
int main()
{
cout << "Welcome to the 99 Bottles of Beer Song Program!" << endl;
cout << "Progam programmed in 2010 by Pasaria." << endl;
system("PAUSE"
while(1)
{
if( a >= 3) {
cout << a << " bottles of beer on the wall " << a << " bottles of beer." << endl;
cout << " " << endl;
a--;
Sleep(3100);
cout << "Take one down and pass it around, " << a << " bottles of beer on the wall." << endl;
}
else {
a--;
cout << "Take one down and pass it around, " << a << " bottle of beer on the wall." << endl;
cout << " " << endl;
cout << "No more bottles of beer on the wall, no more bottles of beer. " << endl;
cout << "Go to the store and buy some more, 99 bottles of beer on the wall." << endl;
system("PAUSE"
break;
}
}
}
#include <iostream>
#include <string>
int main() {
std::string s[9] = {" bottle", " bottles", " of beer", " on the wall",
"Take one down and pass it around, ", "No more", " no more", "1",
"Go to the store and buy some more, 99"};
for(int i = 99; i > 0; i--) {
if (i < 3)
std::cout << i << s[i - 1] << s[2] << s[3] << ", " << i << s[i- 1] << s[2]
<< ".\n" << s[4] << s[i + 5] << s[(i * -1) + 2] << s[2] << s[3] << ".\n\n";
else
std::cout << i << s[1] << s[2] << s[3] << ", " << i << s[1] << s[2]
<< ".\n" << s[4] << i - 1 << s[1] << s[2] << s[3] << ".\n\n";
}
std::cout << s[5] << s[1] << s[2] << s[3] << ',' << s[6] << s[1] << s[2]
<< ".\n" << s[8] << s[1] << s[2] << s[3] << '.';
std::cin.get();
return 0;
}