Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 15,538 times

Contents

Related Categories

99 Bottles - The Approach

The Approach

It would be simple, although very dull, to just make a quick loop to go from 99 to 0:

// A very dull, lifeless way to sing the 99 Bottles song.

using System;

public class SingTheSong
{
   public static void Main()
   {
       int count = 99;

       while (count < 99)
       {
           System.Console.WriteLine("{0} bottles of beer on the wall,", count);
           System.Console.WriteLine("{0} bottles of beer.", count);
           System.Console.WriteLine("Take one down, pass it around,");
           --count;
           System.Console.WriteLine("{0} bottles of beer on the wall,", count);
           System.Console.WriteLine();
       }
   }
}

There's no cachet in that, if you ask me. What if I want to drink something else? What if I want more (or less) than 99? What do I do when I run out? Do I really want to sing "1 bottles of beer"? How do I send the output to, say, a browser instead of the console?

No, that just wouldn't do.

Comments