Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Parallel C#

(Asynchronous version)

Date:03/29/08
Author:Vadim B. Guzev
URL:n/a
Comments:0
Info:http://www.parallelcsharp.com
Score: (3.50 in 4 votes)
/**
 * This little program generate the lyrics to the song 
 * 99 Bottles of Beer as an output. 
 * In case you do not know the song, you will find the lyrics 
 * to the song here:
 * http://www.99-bottles-of-beer.net/lyrics.html
 *
 * This version is made for manycore processors, 
 * i.e. this is not a cluster version!
 * More information on site http://www.parallelcsharp.com
 *
 **/
using System;

public class Bottles99 {
 static string getPart( int nBottles ) { 
  // Just a helper function which spells "bottles"...
  return nBottles == 1 ? 
   "1 bottle" : nBottles == 0 ? "no more bottles" : nBottles + " bottles";
 }

 static async SingAndDrink() & static void PassMicrophone( int nBottles ) {
  string bottles = getPart( nBottles );
  Console.WriteLine( bottles.Replace('n','N') + " of beer on the wall, " + 
   bottles + " of beer." );

  nBottles--;
  bottles = getPart( nBottles );

  if (nBottles >= 0) Console.WriteLine( 
   "Take one down and pass it around, " + bottles + " of beer on the wall." );
  else Console.WriteLine( 
   "Go to the store and buy some more, 99 bottles of beer on the wall." );
  Console.WriteLine();

  if ( nBottles >= 0 ) PassMicrophone( nBottles );
 }

 public static void Main( string[] args ) {
  for ( int i = 0; i < 100; i++ ) 
   Bottles99.SingAndDrink(); // We'll have 100 singers
  Bottles99.PassMicrophone( 99 );
 }
}

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Movable versionVadim B. Guzev03/29/080

Comments

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!

Name:

eMail:

URL:

Security Code:
  
Comment: