* User defined TYPE error
@ 2002-12-25 20:04 J.Matthews
2002-12-28 21:01 ` James S. Rogers
0 siblings, 1 reply; 2+ messages in thread
From: J.Matthews @ 2002-12-25 20:04 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2400 bytes --]
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);
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;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: User defined TYPE error
2002-12-25 20:04 User defined TYPE error J.Matthews
@ 2002-12-28 21:01 ` James S. Rogers
0 siblings, 0 replies; 2+ messages in thread
From: James S. Rogers @ 2002-12-28 21:01 UTC (permalink / raw)
[-- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-12-28 21:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-25 20:04 User defined TYPE error J.Matthews
2002-12-28 21:01 ` James S. Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox