How to resolve the algorithm 99 bottles of beer step by step in the Haxe programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm 99 bottles of beer step by step in the Haxe programming language

Table of Contents

Problem Statement

Display the complete lyrics for the song:     99 Bottles of Beer on the Wall.

The lyrics follow this form: ... and so on, until reaching   0     (zero). Grammatical support for   1 bottle of beer   is optional. As with any puzzle, try to do it in as creative/concise/comical a way as possible (simple, obvious solutions allowed, too).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm 99 bottles of beer step by step in the Haxe programming language

Source code in the haxe programming language

class RosettaDemo
{
    static public function main()
    {
        singBottlesOfBeer(100);
    }

    static function singBottlesOfBeer(bottles : Int)
    {
        var plural : String = 's';

        while (bottles >= 1)
        {
            Sys.println(bottles + " bottle" + plural + " of beer on the wall,");
            Sys.println(bottles + " bottle" + plural + " of beer!");
            Sys.println("Take one down, pass it around,");
            if (bottles - 1 == 1)
            {
                plural = '';
            }

            if (bottles > 1)
            {
                Sys.println(bottles-1 + " bottle" + plural + " of beer on the wall!\n");
            }
            else
            {
                Sys.println("No more bottles of beer on the wall!");
            }
            bottles--;
        }
    }
}


class Bottles {

    static public function main () : Void {
        singBottlesOfBeer(100);
    }


    macro static public function singBottlesOfBeer (bottles:Int) {
        var lines = [];
        var s : String = 's';

        var song : String = '';
        while( bottles >= 1 ){
            song += '$bottles bottle$s of beer on the wall,\n';
            song += '$bottles bottle$s of beer!\n';
            song += 'Take one down, pass it around,\n';

            bottles --;

            if( bottles > 1 ){
                song += '$bottles bottles of beer on the wall!\n\n';
            }else if( bottles == 1 ){
                s = '';
                song += '$bottles bottle of beer on the wall!\n\n';
            }else{
                song += 'No more bottles of beer on the wall!\n';
            }
        }

        return macro Sys.print($v{song});
    }

}


  

You may also check:How to resolve the algorithm Split a character string based on change of character step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Factorial step by step in the jq programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Eiffel programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the Aime programming language
You may also check:How to resolve the algorithm Doubly-linked list/Traversal step by step in the Axe programming language