comp.lang.ada
 help / color / mirror / Atom feed
* Re: interest computing problem
@ 2003-09-22  0:44 Robert I. Eachus
  0 siblings, 0 replies; 14+ messages in thread
From: Robert I. Eachus @ 2003-09-22  0:44 UTC (permalink / raw)


 > That is definitely something that I need to look into.. making this 
program as you said a little more robust.

This is why it is such a good idea to 'echo back' the input data as your 
program sees it. There are all sorts of conversion and accuracy issues, 
plus the fact that your program can never tell if the way it interprets 
the numbers is the way that the user of the program intended.( I would 
avoid anthromorphizing the software here, except that makes it even more 
complicated to understand. The user may be a later edition of the 
author, as in this case. But from the program's point of view, the 
assumptions never changed...) If the percentage rate had been 'echoed' 
as 0.02% you would have seen the mistate immediately--or at least sooner.




^ permalink raw reply	[flat|nested] 14+ messages in thread
* interest computing problem
@ 2003-09-16 15:27 Andrew
  2003-09-16 15:54 ` Ludovic Brenta
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Andrew @ 2003-09-16 15:27 UTC (permalink / raw)



ok I've run into a snag  .. and i'm hoping that a programmer can help me 
out.

here is a copy of my program (written in Ada)

====
-- computes Interest on money invested

with TEXT_IO;
use TEXT_IO;

procedure Interest is
    Initialamt : Float;
    Interest : Float;
    TimeNWeeks : Integer;
    DRate : Float;
    Days : Integer;
    Balance : Float;

    package NUMBER_IO is new INTEGER_IO(INTEGER);
    use NUMBER_IO;
    package Float1_IO is new Float_IO(FLOAT);
    use Float1_IO;

begin
    New_Line;
    Put ("How much money do you have-Please add cents? example 365.22 ");
    Get (Initialamt);

Put ("What is the interest you will receive? ");
    Get (Interest);
 

    Put ("How long will it be invested in weeks? ");
    Get (TimeNWeeks);
 

    New_Line;
 

    Days:=TimeNWeeks * 7;
    DRate:=(Interest/100.0)/365.0;
    Balance:=Initialamt * (1.0+DRate)**Days;
 

    New_Line;
    Put ("Your ending balance will be ");
    Put (Balance);
 

    New_Line;
end Interest;


========================================


now here is the output from when I try to run the program
==================
How much money do you have-Please add cents? .02
What is the interest you will receive? 25
How long will it be invested in weeks? 4


Your ending balance will be  2.03872E-02
[andrew@stc program]$ ./interest

How much money do you have-Please add cents? .02
What is the interest you will receive? .25
How long will it be invested in weeks? 4


Your ending balance will be  2.00038E-02

============

but I'm hoping that this is just a simple case of I .. well *L* I'm 
hoping this is a simple error that I'm overlooking..

sub-note : this program is directly copied from a printout of a program 
that I wrote in college (and it worked on the colleges computers).

By the way I'm writing this on a Red Hat Linux 9.0 computer (I don't 
think that would matter but ..)




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

end of thread, other threads:[~2003-09-22  0:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-22  0:44 interest computing problem Robert I. Eachus
  -- strict thread matches above, loose matches on Subject: below --
2003-09-16 15:27 Andrew
2003-09-16 15:54 ` Ludovic Brenta
2003-09-16 17:21   ` tmoran
2003-09-17  4:26     ` Andrew
2003-09-16 21:52 ` Robert I. Eachus
2003-09-17  3:48   ` Andrew
2003-09-17  4:28     ` Andrew
2003-09-17  5:18     ` tmoran
2003-09-17  7:47       ` Andrew
2003-09-17 16:05         ` Andrew
2003-09-17 16:32           ` Martin Dowie
2003-09-19  4:07 ` Leon Winslow
2003-09-21 22:55   ` Andrew

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