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

* Re: Formatting output
  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
  0 siblings, 2 replies; 5+ messages in thread
From: Stephen Leake @ 2001-11-14 22:14 UTC (permalink / raw)


cptnben@gisco.net (Ben) writes:

> 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.

This sounds like a homework problem, so I'll only give a hint; look at
the parameters Fore and Aft in Ada.Text_IO.Float_IO. Then go ask your
instructor, and your textbook.

If this is not a homework problem, and that does not help, come back
for more.

> <snip> 
-- 
-- Stephe



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

* Re: Formatting output
  2001-11-14 22:14 ` Stephen Leake
@ 2001-11-14 22:26   ` Marin David Condic
  2001-11-15 17:32   ` Ben
  1 sibling, 0 replies; 5+ messages in thread
From: Marin David Condic @ 2001-11-14 22:26 UTC (permalink / raw)


See also Ada Reference Manual (ARM) 3.5.9 concerning Decimal Fixed Point
Types and ARM Appendix F.3 - Edited Output For Decimal Types. You can pretty
much use this stuff to do all the clever formatting you might find in Cobol
programs & is a natural for currency.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
news:uy9l9xaod.fsf@gsfc.nasa.gov...
>
> This sounds like a homework problem, so I'll only give a hint; look at
> the parameters Fore and Aft in Ada.Text_IO.Float_IO. Then go ask your
> instructor, and your textbook.
>
> If this is not a homework problem, and that does not help, come back
> for more.






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

* Re: Formatting output
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Ben @ 2001-11-15 17:32 UTC (permalink / raw)


Actually it was a homework problem. This was the first assigned lab
from my 1999 Introductory Programming class (PASCAL). Now in my Junior
year, I am in an upper level Programming Languages course. Our final
project was to write a manual on an assigned language (mine was 35
pages) I got Ada. One of the things we have to do is give a 2.5 hour
presentation on the language, and assign homework based on your
presentation and manual. I recycled this lab since it is fairly
simple.  Now I am trying to convert it from the original PASCAL to Ada
so I can have a working program before I assign it with my
presentation in two weeks.
I should also correct my post by saying that FLOAT_IO is not used at
all in my current code.
Thanks,
Ben

Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> wrote in message news:<uy9l9xaod.fsf@gsfc.nasa.gov>...
> cptnben@gisco.net (Ben) writes:
> 
> > 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.
> 
> This sounds like a homework problem, so I'll only give a hint; look at
> the parameters Fore and Aft in Ada.Text_IO.Float_IO. Then go ask your
> instructor, and your textbook.
> 
> If this is not a homework problem, and that does not help, come back
> for more.
> 
> > <snip>



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

* Re: Formatting output
  2001-11-15 17:32   ` Ben
@ 2001-11-15 18:09     ` Marin David Condic
  0 siblings, 0 replies; 5+ messages in thread
From: Marin David Condic @ 2001-11-15 18:09 UTC (permalink / raw)


Well, to suggest a possible solution to the problem of getting a floating
point number represented as currency in either a string or in output to a
text file, you'll have to be a bit more specific as to what constraints you
want to put on it.

Ada.Text_IO.Float_IO is one means of doing it, but if you're going to rule
that out, there aren't a lot of alternatives. You could potentially convert
the value to a decimal fixed and use either the appendix I cited elsewhere
or you're right back to Ada.Text_IO... subpackages. Or you can totally
Roll-Your-Own by doing math ops on the number to get individual digits and
convert the digits to characters & build your own string out of it.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Ben" <cptnben@gisco.net> wrote in message
news:bf8dbe70.0111150932.536dad02@posting.google.com...
> I should also correct my post by saying that FLOAT_IO is not used at
> all in my current code.






^ 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