[1+1=2]
OneAndOneIs2

Fri, Jun 01, 2007

[Link][Icon]You know you're bored...

...when you start working out how to make a program to output the "10 green bottles" song.

(That's the UK equivalent of the "bottles of beer" song, if you're American)

And you know you're REALLY bored when you look up the bash codes so the word "green" is coloured green.

Dread to think what I'll do to it next.

Friday afternoons, eh?

[More:]

#include <stdio.h>

#define StartNum 10

void bottlenum(int i);

int main()
{
        int i = StartNum;

        while (i > 0)
        {
                /* Start only the first verse with the "There were" line */
                if (i == StartNum)
                {
                        printf("There were ");
                        bottlenum(i);
                }
                bottlenum(i);
                printf("And if one \e[32mgreen\e[0m bottle should accidentally fall\nThere'd be ");
                bottlenum(--i);
        }
        return 0;
}

/* This function prints the repetitive part of the song */
void bottlenum(int i)
{
                printf("%d \e[32mgreen\e[0m bottle", i);
                if (i > 1)
                        putchar('s');
                printf(", sitting on the wall\n");
}
6 comments • Categories: Omni, Programming

Comments:

Comment from: hari [Member] Email · http://hari.literaryforums.org
Make it interactive now. Ask the user to input the number of bottles instead of defining it as a macro.
PermalinkPermalink 01/06/07 @ 17:23
Comment from: oneandoneis2 [Member] · http://geekblog.oneandoneis2.org/
Yeah, I did consider that.. but I couldn't remember how to call scanf, couldn't be bothered to look it up, and besides, the song always starts from 10 :o)

(Unless you're very bored, in which case it goes up by orders of magnitude, relative to just how bored you are ;o)
PermalinkPermalink 01/06/07 @ 19:57
Comment from: Andrew [Visitor] Email
Save me a Google search... how does the song go? (Yes, I'm obviously American, with my bottles of beer on the wall :P)
PermalinkPermalink 02/06/07 @ 00:58
Comment from: Andrew [Visitor] Email
Crap... didn't see the "More" button. Nevermind.
PermalinkPermalink 02/06/07 @ 00:59
Comment from: alison [Member] · http://www.creativehedghog.com
a friend and I sang 1,000 green bottles... we were banned from the house.
PermalinkPermalink 02/06/07 @ 01:42
Comment from: hari [Member] Email · http://hari.literaryforums.org
Next step: start writing GUI programs in QT or GTK.
PermalinkPermalink 02/06/07 @ 02:50

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

Categories

August 2008
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Search

Misc

XML Feeds

What is this?
eXTReMe Tracker

Valid XHTML 1.0 Transitional

Valid CSS!

[Valid RSS feed]

powered by
b2evolution

blank