comp.lang.ada
 help / color / mirror / Atom feed
From: Leon Winslow <leon.winslow@notes.udayton.edu>
To: Andrew <eagletalon@chartermi.net>
Subject: Re: interest computing problem
Date: Fri, 19 Sep 2003 00:07:22 -0400
Date: 2003-09-19T00:07:22-04:00	[thread overview]
Message-ID: <3F6A80FA.3ECF8B55@notes.udayton.edu> (raw)
In-Reply-To: vmeb0k2buli9cf@corp.supernews.com

Andrew

Your program is a good example of a student homework program.  It works, as
long as you remember all of the assumptions you made in writing it.  This is
about as much as most instructors expect of their students and I'm sure you
got a good grade on it.

It might be instructive, however, to rewrite it in a more robust version.
For example, define some data types and check the input for valid values.
Thus, real money is always integers (minimum value is one cent, not .00001 or
some such) and interest is either an integer type 3% or a float type .12%
depending on what you want.  Note this will require you to define exactly how
one computes interest times dollars.  All of these details are one reason
real programs tend to look long and complicated to outsiders.

If you can do a robust version of this problem, you will have accomplished
something past what your instructor expected.

Its always good to see another new Ada programmer.  Good luck in your
endeavors.

Lee Winslow

Andrew wrote:

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




  parent reply	other threads:[~2003-09-19  4:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-16 15:27 interest computing problem 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-17 16:36           ` Stupid! -was- " Andrew
2003-09-17 17:00             ` Stephane Richard
2003-09-17 17:15               ` Andrew
2003-09-19  4:07 ` Leon Winslow [this message]
2003-09-21 22:55   ` Andrew
  -- strict thread matches above, loose matches on Subject: below --
2003-09-22  0:44 Robert I. Eachus
replies disabled

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