comp.lang.ada
 help / color / mirror / Atom feed
* School Assignment--Can this be simplified?
@ 2000-08-30  0:00 N J Chackowsky
  2000-08-30  0:00 ` tmoran
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: N J Chackowsky @ 2000-08-30  0:00 UTC (permalink / raw)


Hello... I'm about to teach ADA95 for the first time, and I've come up
with an assignment which helps students encode formulas. I'm using a
formula to translate from temperature and dew point to relative
humidity. The trouble is, I need to use the Pow function, so I need with
ada.numerics.aux. Does this look about right, and could it be
simplified. 

--HUMIDITY.ADB
-----------------------------------------------------------------------
--| Calculates and displays the relative humidity based on 
--| the temperature and dew point.
--|
--| Author: N J Chackowsky, Brandon School Division No. 40
--| Last modified: 2000 08 30
-----------------------------------------------------------------------

   with ada.text_io;
   with ada.integer_text_io;
   with ada.float_text_io;

	-- Normally, we'd use ada.numerics, but we also need the Pow, Double,
and Float
	-- functions. Ada.Numerics.Aux contains these.
   with ada.numerics.aux; use ada.numerics.aux;

   procedure humidity is
   
      tempc, tempk : float;   	-- temperature in C and K
      dewc, dewk : float;	-- dew point in C and K
      vp, svp : float;		-- vapour pressure and saturated vapour pressure
      rh : float;		-- relative humidity  
   
   begin
   
   	-- Get the temperature and dew point
      ada.text_io.put(item => "What is the temperature in degrees
Celcius? ");
      ada.float_text_io.get(item => tempc);
      ada.text_io.put(item => "What is the dew point in degrees Celcius?
");
      ada.float_text_io.get(item => dewc);
   
   	-- Convert from C to K
      tempk := tempc + 273.15;
      dewk := dewc + 273.15;
   
   	-- Calculate vapour pressure and saturated vapour pressure
      vp := float(pow(2.7183, double(-5438.0 / dewk + 21.72)));
      svp := float(pow(2.7183,double(-5438.0 / tempk + 21.72)));
   
   	-- Calculate relative humidity. Multiply by 100.0 for display as a %
      rh := vp / svp * 100.0;
   
   	-- Display results
      ada.text_io.put(item => "The relative humidity is ");
      ada.float_text_io.put(item => rh, fore => 1, aft => 1, exp => 0);
      ada.text_io.put(item => "%");
   
   end humidity;

Question: Why do I need the double( ) around the expression
-5438.0/dewk+21.72, but not around the literal 2.7183?

Thanks for any input.

Nick.




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

end of thread, other threads:[~2000-09-02  3:12 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-30  0:00 School Assignment--Can this be simplified? N J Chackowsky
2000-08-30  0:00 ` tmoran
2000-08-30  0:00 ` Keith Thompson
2000-08-30  0:00 ` Pascal Obry
2000-08-31  0:00 ` Martin Dowie
2000-08-31 11:31   ` Simon Wright
2000-08-31 11:51     ` Martin Dowie
2000-08-31 18:35   ` N J Chackowsky
2000-08-31 19:19     ` N J Chackowsky
2000-08-31 19:33       ` Pascal Obry
2000-08-31 23:03         ` Nick J Chackowsky
2000-09-01  1:02         ` tmoran
2000-09-01  4:14           ` Robert Dewar
2000-09-01 17:51             ` tmoran
2000-09-02  3:12               ` Robert Dewar

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