Language C++
(hacking style)
Date: | 04/20/05 |
Author: | Tim Robinson |
URL: | n/a |
Comments: | 14 |
Info: | n/a |
Score: | (2.98 in 133 votes) |
// 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 |
---|---|---|---|---|
object-oriented version | Tim Robinson | 04/20/05 | 4 | |
extreme template metaprogramming | Richard Wolf | 04/20/05 | 5 | |
meta programming | Arion Lei | 04/20/05 | 5 | |
Preprocessor & self-include recursion | Chocapic | 02/27/07 | 6 | |
feature creep | Jono | 04/27/09 | 1 | |
most extreme template metaprogramming | Henrik Theiling | 12/04/11 | 0 | |
7 | Jono | 04/15/09 | 0 | |
ob fuscated | Tapi (Paddy O'Brien) | 08/11/05 | 4 | |
GUI version | Martyn Davies | 05/28/05 | 1 |
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
Zak said on 05/17/05 21:53:23
nice, may be shorter
ksdkjcjdas said on 01/10/06 11:28:23
Well, just add in the last part and you will recreate the entire song...
Mick said on 04/06/06 21:24:23
I like the never ending thing.
PhreakerD7 said on 04/08/06 20:44:32
Yeah. I saw the first one that was long as hell and was thinking "WHILE loop, anyone?"
freacker4life said on 04/29/06 10:16:24
Pretty Good. There's just one problem. After executing this program, it quits automatically. I think its better to add a "cin.get();" after the loop at least.
P1xel said on 03/29/07 02:27:48
Yes, you should add it at the end...
prushik said on 12/03/07 20:26:05
Whats up with the while loop? Why does nobody think to use a for loop for this?
catnappa said on 10/22/08 22:00:29
no simply add
system ("pause"
one line before the return to make it wait for a keyboard button press.
Michael said on 03/18/09 07:49:35
No, catnappa, cin.get() is correct. Not only is system("pause" a gigantic security hole, it only works on windows/MS-DOS, while C++ is portable. system("pause" should NEVER be used outside of crappy little homework assignments or code that is not going to be released. Granted, in something like this, it's not that big of a deal, but why form bad coding habits? Use cin.get() (there are actually other tricks for this that work better, but cin.get() works ok), not system("ANYTHING, EVER"
Jono said on 04/17/09 02:30:22
it doesn't write the last verse.
rahman said on 05/19/09 12:50:55
hmm...
it's easy!
Pasaria said on 01/06/10 16:42:01
Got this version that I programmed. Includes ending.
#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;
}
}
}
penoo said on 05/31/10 06:35:03
Lurveleven said on 05/31/10 11:57:17
Pretty far from giving the correct result.