home *** CD-ROM | disk | FTP | other *** search
- // ========================================================================
- // Fruit.cs
- //
- // This program adds up the costs and quantities of selected fruit types
- // and outputs the results to the display
- // ========================================================================
-
- function runFruit()
- // ----------------------------------------------------
- // Entry point for the program.
- // ----------------------------------------------------
- {
- $bananaCost=1.15;// initilize the value of our variables
- $appleCost=0.55; // (we don't need to repeat the above
- $numApples=3; // comment for each initialization, just
- $numBananas=1; // group the init statements together.)
-
- $numFruit=0; // always a good idea to initialize *all* variables!
- $total=0; // (even if we know we are going to change them later)
-
- echo("Cost of Bananas(ea.):$"@$bananaCost);
- // the value of $bananaCost gets concatenated to the end
- // of the "Cost of Bananas:" string. Then the
- // full string gets printed. same goes for the next 3 lines
- echo("Cost of Apples(ea.):$"@$appleCost);
- echo("Number of Bananas:"@$numBananas);
- echo("Number of Apples:"@$numApples);
-
- $numFruit=$numBananas+$numApples; // add up the total number of fruits
- $total = ($numBananas * $bananaCost) +
- ($numApples * $appleCost); // calculate the total cost
- //(notice that statements can extend beyond a single line)
-
- echo("Total amount of Fruit:"@$numFruit); // output the results
- echo("Total Price of Fruit:$"@$total@"0");// add a zero to the end
- // to make it look better on the screen
- }