comp.lang.ada
 help / color / mirror / Atom feed
* Formatting output
@ 2001-11-14 21:58 Ben
  2001-11-14 22:14 ` Stephen Leake
  0 siblings, 1 reply; 5+ messages in thread
From: Ben @ 2001-11-14 21:58 UTC (permalink / raw)


I am using the Linux version of the GNAT Ada compiler.

I am trying to format a floating point output from Scientific Notation
to a US currency standard. I am new to Ada and the only library I am
using is TEXT_IO. I don't know for certain what I have available for
other libraries.
How might one make the following code (simple program) output the
final results (TotFly and TotDri) as U.S. currency.

Thanks,
Ben

with    TEXT_IO,
        FLOAT_TEXT_IO;
use     TEXT_IO,
        FLOAT_TEXT_IO;
procedure LAB01 is
        --  Programmer:         Benjamin  Hodge
        --  Date  Due:          Thursday, September  16  1999
        --  FileName:           lab01.adb
        --  Project Number:     Project01
        --  Project  Description:
        --      This  program  is  to  be  used  to  calculate  the 
total
        --  costs  for  a  trip  to  Florida, using  given  figures,
with
        --  the  options  of  driving  or  flying. The  program  will 
        --  calculate  and  then  display  the  total  cost  for  each
        --  option, allowing  a  vacationer  to  choose  the  least
        --  expensive  option.
        
        FuelPrice : float := 1.359;     --  $ 1.359 per  gallon
        RoomPrice : float := 49.95;     --  $49.95  per  night 
        TicketPrice : float := 245.76;  --  $245.76 per  person
        CarRentPrice : float := 67.5;   --  $ 67.50 per  day
        MealPrice : float := 7.5;       --  $ 7.50 per  person/per 
meal
        MealNum : float := 27.0 ;       --  27 meals per  person
        NumPeople : float := 2.0;       --  Two people
        MilToFla : float := 1800.0;     --  1800 miles one - way
        SightCMil : float := 30.0;      --  30.0 miles per - day
        SightCFly : float := 8.0;       --  8 sight seeing days if
flying
        SightCDri : float := 6.0;       --  6 sight seeing days if
driving
        RentalMPG : float := 32.0;      --  32 miles Per Gallon
        MilesTravD : float;     --  Total, driving
        MilesTravF : float;     --  Total, flying
        FuelCostD : float;      --  Total
        FuelCostF : float;      --  Total
        FoodCost : float;       --  Total
        RoomCost : float;       --  Total
        RentalCost : float;     --  Total
        TicketCost : float;     --  Total
        TotFly : float;         --  Total cost  of  flying
        TotDri : float;         --  Total cost  of  driving

begin
        -- Calculate Total Miles Traveled Driving
        MilesTravD := (MilToFla*2.0) + (SightCDri*SightCMil);
        
        -- Calculate Total Miles Traveled Flying
        MilesTravF := SightCFly*SightCMil;
        
        -- Calculate Total Fuel Cost driving
        FuelCostD := MilesTravD/(RentalMPG*FuelPrice);

        -- Calculate Total Fuel Cost flying
        FuelCostF := MilesTravF/(RentalMPG*FuelPrice);
        
        -- Calculate Total Food Cost
        FoodCost := MealNum*NumPeople*MealPrice;
        
        -- Calculate Total Room Cost
        RoomCost := RoomPrice*9.0;

       -- Calculate Total Rental Car Price
        RentalCost := CarRentPrice*9.0;
        
        -- Calculate Total Plane Ticket Cost
        TicketCost := TicketPrice*NumPeople;
        
        -- Calculate Total Cost of Flying
        TotFly := FuelCostF + RentalCost + RoomCost + FoodCost +
TicketCost;
        
        -- Calculate Total Cost of Driving
       TotDri := FuelCostD + RentalCost + RoomCost + FoodCost;
        
        -- Display Results
        put ("Total Cost of Trip, flying  :      "); put(TotFly'img);
        NEW_LINE;
        put ("Total Cost of Trip, driving  :      "); put(TotDri'img);
        NEW_LINE;
end LAB01;



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-11-15 18:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-14 21:58 Formatting output Ben
2001-11-14 22:14 ` Stephen Leake
2001-11-14 22:26   ` Marin David Condic
2001-11-15 17:32   ` Ben
2001-11-15 18:09     ` Marin David Condic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox