comp.lang.ada
 help / color / mirror / Atom feed
* Problem with Floating Points
@ 2007-12-14  4:19 DarthBob88
  2007-12-14  4:49 ` DarthBob88
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: DarthBob88 @ 2007-12-14  4:19 UTC (permalink / raw)


I'm trying to use a Percentage type to show how often a given
condition occurred; like percent := matches/attempts. The only problem
is, it keeps outputting 0% for the result percentage. I have been
unable to get it to change its output, even to another nonsense answer
like that. Here follows my program, without the irrelevant portions.

with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;

procedure test is
        type Percentage is Delta 0.01 range 0.00 .. 100.00;
        --Runs from 0 to 100%, and goes to two decimal places.

        Successes : Integer := 0;
        Attempts : Integer := 0;
        Output : Percentage;
begin

         loop
                Attempts := Attempts + 1;
                --when we get a success
               Successes := Successes + 1;

                exit when iterator = 1000;
         end loop;
         Output := 100.00 * (Successes / Iterator);
         Put_Line("Attempts: " & Integer'Image(Attempts));
         New_Line;
         Put_Line("Successes: " & Integer'Image(Successes));
         New_Line;
         Put_Line("Percentage of Successes: " &
Percentage'Image(Output));
end Test;

I've been able to get real outputs for Attempts and Successes, but
nothing at all for Output. I've been looking through every other
source available, but nothing had an answer for me.



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

* Re: Problem with Floating Points
  2007-12-14  4:19 Problem with Floating Points DarthBob88
@ 2007-12-14  4:49 ` DarthBob88
  2007-12-14  6:48 ` tmoran
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: DarthBob88 @ 2007-12-14  4:49 UTC (permalink / raw)


On Dec 13, 8:19 pm, DarthBob88 <darthbo...@gmail.com> wrote:
> I'm trying to use a Percentage type to show how often a given
> condition occurred; like percent := matches/attempts. The only problem
> is, it keeps outputting 0% for the result percentage. I have been
> unable to get it to change its output, even to another nonsense answer
> like that. Here follows my program, without the irrelevant portions.
>
> with Ada.Text_IO, Ada.Integer_Text_IO;
> use Ada.Text_IO, Ada.Integer_Text_IO;
>
> procedure test is
>         type Percentage is Delta 0.01 range 0.00 .. 100.00;
>         --Runs from 0 to 100%, and goes to two decimal places.
>
>         Successes : Integer := 0;
>         Attempts : Integer := 0;
>         Output : Percentage;
> begin
>
>          loop
>                Attempts := Attempts + 1;
>                --when we get a success
>                Successes := Successes + 1;
>
>                exit when iterator = 1000;
>          end loop;
>          Output := 100.00 * (Successes / Iterator);
>          Put_Line("Attempts: " & Integer'Image(Attempts));
>          New_Line;
>          Put_Line("Successes: " & Integer'Image(Successes));
>          New_Line;
>          Put_Line("Percentage of Successes: " &
> Percentage'Image(Output));
> end Test;
>
> I've been able to get real outputs for Attempts and Successes, but
> nothing at all for Output. I've been looking through every other
> source available, but nothing had an answer for me.
Never mind, it works the way it should now. Apparently, I wasn't going
out to enough places for Successes/Iterator to actually show up as a
number.



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

* Re: Problem with Floating Points
  2007-12-14  4:19 Problem with Floating Points DarthBob88
  2007-12-14  4:49 ` DarthBob88
@ 2007-12-14  6:48 ` tmoran
  2007-12-14  9:33 ` Keith Thompson
  2007-12-14 14:15 ` Jeffrey Creem
  3 siblings, 0 replies; 5+ messages in thread
From: tmoran @ 2007-12-14  6:48 UTC (permalink / raw)


>        Output := 100.00 * (Successes / Iterator);
  If Successes < Iterator the integer division will result in 0.



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

* Re: Problem with Floating Points
  2007-12-14  4:19 Problem with Floating Points DarthBob88
  2007-12-14  4:49 ` DarthBob88
  2007-12-14  6:48 ` tmoran
@ 2007-12-14  9:33 ` Keith Thompson
  2007-12-14 14:15 ` Jeffrey Creem
  3 siblings, 0 replies; 5+ messages in thread
From: Keith Thompson @ 2007-12-14  9:33 UTC (permalink / raw)


DarthBob88 <darthbob88@gmail.com> writes:
> I'm trying to use a Percentage type to show how often a given
> condition occurred; like percent := matches/attempts. The only problem
> is, it keeps outputting 0% for the result percentage. I have been
> unable to get it to change its output, even to another nonsense answer
> like that. Here follows my program, without the irrelevant portions.
>
> with Ada.Text_IO, Ada.Integer_Text_IO;
> use Ada.Text_IO, Ada.Integer_Text_IO;
>
> procedure test is
>         type Percentage is Delta 0.01 range 0.00 .. 100.00;
>         --Runs from 0 to 100%, and goes to two decimal places.
>
>         Successes : Integer := 0;
>         Attempts : Integer := 0;
>         Output : Percentage;
> begin
>
>          loop
>                 Attempts := Attempts + 1;
>                 --when we get a success
>                Successes := Successes + 1;
>
>                 exit when iterator = 1000;
>          end loop;
>          Output := 100.00 * (Successes / Iterator);
>          Put_Line("Attempts: " & Integer'Image(Attempts));
>          New_Line;
>          Put_Line("Successes: " & Integer'Image(Successes));
>          New_Line;
>          Put_Line("Percentage of Successes: " &
> Percentage'Image(Output));
> end Test;

It would help if you posted your actual program.  The above doesn't
compile (iterator is undefined).

> I've been able to get real outputs for Attempts and Successes, but
> nothing at all for Output. I've been looking through every other
> source available, but nothing had an answer for me.

What do you mean by "nothing at all"?  Does it print 0.0?  Does it
really not print anything?

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



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

* Re: Problem with Floating Points
  2007-12-14  4:19 Problem with Floating Points DarthBob88
                   ` (2 preceding siblings ...)
  2007-12-14  9:33 ` Keith Thompson
@ 2007-12-14 14:15 ` Jeffrey Creem
  3 siblings, 0 replies; 5+ messages in thread
From: Jeffrey Creem @ 2007-12-14 14:15 UTC (permalink / raw)


DarthBob88 wrote:
> I'm trying to use a Percentage type to show how often a given
> condition occurred; like percent := matches/attempts. The only problem
> is, it keeps outputting 0% for the result percentage. I have been
> unable to get it to change its output, even to another nonsense answer
> like that. Here follows my program, without the irrelevant portions.
> 
> with Ada.Text_IO, Ada.Integer_Text_IO;
> use Ada.Text_IO, Ada.Integer_Text_IO;
> 
> procedure test is
>         type Percentage is Delta 0.01 range 0.00 .. 100.00;
>         --Runs from 0 to 100%, and goes to two decimal places.
> 

This is a fixed point type not a floating point type. Also note that the 
comment below adds exactly zero value since it just says the same thing 
as the type. Comment why not the obvious what.




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

end of thread, other threads:[~2007-12-14 14:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-14  4:19 Problem with Floating Points DarthBob88
2007-12-14  4:49 ` DarthBob88
2007-12-14  6:48 ` tmoran
2007-12-14  9:33 ` Keith Thompson
2007-12-14 14:15 ` Jeffrey Creem

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