home *** CD-ROM | disk | FTP | other *** search
- // ========================================================================
- // FermentedFruit.cs
- //
- // Solution to the anti-optimization challenge
- // this uses no loops at all
- // ========================================================================
-
- function runFermentedFruit()
- // ----------------------------------------------------
- // Entry point for the program.
- // ----------------------------------------------------
- {
- //
- // ----------------- Initialization ---------------------
- //
-
- %costBananas = 1.15; // initilize the price values
- %costApples = 0.55;
- %costOranges = 0.55;
- %costMangos = 1.90;
- %costPears = 0.68;
-
- %quantityBananas = 1; // initilize the quantity values
- %quantityApples = 3;
- %quantityOranges = 4;
- %quantityMangos = 1;
- %quantityPears = 2;
-
- %numFruit=0; // always a good idea to initialize *all* variables!
- %totalCost=0; // (even if we know we are going to change them later)
-
- //
- // ----------------- Computation ---------------------
- //
-
- // Display the known statistics of the fruit collection
-
- echo("Cost of bananas:$" @ %costBananas);
- echo("Number of bananas:" @ %quantityBananas);
- echo("Cost of apples:$" @ %costApples);
- echo("Number of apples:" @ %quantityApples);
- echo("Cost of oranges:$" @ %costOranges);
- echo("Number of oranges:" @ %quantityOranges);
- echo("Cost of mangos:$" @ %costMangos);
- echo("Number of mangos:" @ %quantityMangos);
- echo("Cost of pears:$" @ %costPears);
- echo("Number of pears:" @ %quantityPears);
-
- // count up all the pieces of fruit and calculate the total cost
- %numFruit = %quantityBananas + %quantityApples + %quantityOranges
- + %quantityMangos + %quantityPears;
- %totalCost = (%costBananas * %quantityBananas) +
- (%costApples * %quantityApples) +
- (%costOranges * %quantityOranges) +
- (%costMangos * %quantityMangos) +
- (%costPears * %quantityPears);
-
- // now echo the totals
- echo("Total pieces of Fruit:" @ %numFruit);
- echo("Total Price of Fruit:$" @ %totalCost);
- }
-