comp.lang.ada
 help / color / mirror / Atom feed
From: "James S. Rogers" <jimmaureenrogers@worldnet.att.net>
Subject: Re: User defined TYPE error
Date: Sat, 28 Dec 2002 21:01:51 GMT
Date: 2002-12-28T21:01:51+00:00	[thread overview]
Message-ID: <3joP9.17723$p_6.1375396@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: TrnP9.355$xE1.62211@stones

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2872 bytes --]

"J.Matthews" <boss@thenuthouse.f9.co.uk> wrote in message
news:TrnP9.355$xE1.62211@stones...
> Could someone possibly help. I get an error when I try to GET an amount.
> I can make the program work without the user defined TYPE but I wanted
> to restrict the input to valid monetary amounts i.e ���.pp format
>
> Any help appreciated
>
>
>    with ada.text_io,ada.integer_text_io,ada.float_text_io;
>    use ada.text_io,ada.integer_text_io,ada.float_text_io;
>
>    procedure Money is
>
>       Denomination : array (1..12) of integer :=
> (50,20,10,5,2,1,50,20,10,5,2,1);
>       type my_fixed is delta 0.01 range 0.00..1000.00;
>       Values : array (1..12) of my_fixed :=
>
> (50.00,20.00,10.00,5.00,2.00,1.00,0.50,0.20,0.10,0.05,0.02,0.01);
>       Amount : my_fixed;
>       Count : array (1..12) of integer := (1..12 => 0);
>       Current_Value : integer := 0;
>
>    begin
>          put("Enter Amount ");
>          get(Amount);

Why are you using floating point I/O when you really need
to instantiate Ada.Text_IO.Decimal_IO for your fixed point type?
Your error is that you are trying to input a fixed point type using
a floating point I/O package.

>          Amount := Amount+0.001;            --ADA float number fix
>          Current_value := 1;
>          while Amount >= 0.01 loop
>             while Amount > values(Current_Value) loop
>                Amount := Amount - values(Current_Value);
>                Count(Current_Value) := Count(Current_Value)+1;
>             end loop;
>             Current_Value:=Current_Value+1;
>          End Loop;
>          new_line;
>
>          for x in 1..4 loop
>             if Count(x) >= 1 then
>                put(Count(x));
>                put(" X ");
>                put(character'val (156));
>                put(denomination(x),width=>1);
>                if count(x) >=2 then
>                   put_line(" NOTES");
>                else
>                   put_line(" NOTE");
>                end if;
>             end if;
>          end loop;
>
>          for x in 5..6 loop
>             if Count(x) >= 1 then
>                put(Count(x));
>                put(" X ");
>                put(character'val (156));
>                put(denomination(x),width=>1);
>                if count(x) >=2 then
>                   put_line(" COINS");
>                else
>                   put_line(" COIN");
>                end if;
>             end if;
>          end loop;
>
>          for x in 7..12 loop
>             if Count(x) >= 1 then
>                put(Count(x));
>                put(" X ");
>                put(denomination(x),width=>1);
>                if count(x) >=2 then
>                   put_line("p COINS");
>                else
>                   put_line("p COIN");
>                end if;
>             end if;
>          end loop;
>
>    end money;

Jim Rogers





      reply	other threads:[~2002-12-28 21:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-25 20:04 User defined TYPE error J.Matthews
2002-12-28 21:01 ` James S. Rogers [this message]
replies disabled

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