comp.lang.ada
 help / color / mirror / Atom feed
From: mhall59@mail.us.net (Michael W. Hall)
Subject: File Problem. Please help..
Date: 1996/07/31
Date: 1996-07-31T00:00:00+00:00	[thread overview]
Message-ID: <4tof8o$mgp@news.us.net> (raw)


I am in ad ADA class at school and I am writing a program that reads ina 
string, a float and an integer from a file and then prints a graph.
I keep getting "exception not handled Data_error" when I run this program. I 
have included the data file and code below. It obvouisly is trying to read 
something different, when it is supposed to read an integer. I have put 
arrows in the line of code where it crashes. Also how do I have it read 
string variables of different lengths without know the lengths. The program 
isnt very large, so if you have time look at it and please help me if you 
can. Thanks

mhall59@us.net

****************
File : Data.In *
****************

Orville's Acres
114.8     43801
Hoffman's Hills
 77.2    36229
Jiffy Quick Farm
 89.4    24812
Jolly Good Plantation
183.2   104570
Organically Grown Inc.
 45.5    14683




***************
Program below *
***************

with Text_IO;

procedure Graph2 is

-- This program generates bar graphs for popcorn production.
-- Instantiate packages for numeric I/O

   package Integer_IO is new Text_IO.Integer_IO (Num => Integer);
   package Float_IO is new Text_IO.Float_IO (Num => Float);

-- Variables for main program
   Name : String(1..15);       -- Plant Name
   Result : Float;
   Popcorn_Data : Text_IO.File_Type;
------------------------------------------

procedure Print_Header is

   -- This procedure prints the title for the bar graph.
   -- The scale uses one mark per 250 pint jars.

   begin  -- Print_Header
      Text_IO.Put ("                  Pop Co-Op");
      Text_IO.New_Line;
      Text_IO.Put ("Farm Name                   Production");
      Text_IO.New_Line;
      Text_IO.Put ("                            Thousands of");
      Text_IO.New_Line;
      Text_IO.Put ("                            Pint Jars per Acre");
      Text_IO.New_Line;
      Text_IO.Put ("                               1   2   3   4   5   6");
      Text_IO.New_Line;
      Text_IO.Put ("                            ---|---|---|---|---|---|");
      Text_IO.New_Line;
   end Print_Header;

--------------------------------------------

   procedure Get_Data (Data_File : in Text_IO.File_Type;
		       Pints_Per_Acre : out  Float;
		       Plant_Name : out String) is

   -- This procedure takes an input file as a parameter, reads
   -- the number of pints and number of acres that file.
   Total : Float;
   Acres : Float;
   Pints : Integer;

   begin   -- Get_Data
      Text_IO.Get (File => Data_File, Item => Plant_Name);
      Float_IO.Get (File => Data_File, Item => Acres);
*** crashes ***--->      Integer_IO.Get (File => Data_File, Item => Pints);
      Total := float(pints) / acres;
 
end Get_Data;



------------------------------------------------

   procedure Print_Data (Plant_Name : in String;
			 Total : in Float;
			 Pints_Per_Acre : in Float) is
   -- This procedure prints the asterisk line, one for every 250 thousand.
   Total_Remaining : Float;
   begin  -- Print_Data
      Text_IO.Put (Item => Plant_Name);
      Total_Remaining := Pints_Per_Acre;
      Star_Loop:
         loop
	    exit Star_Loop when Total < 250.0;
	    Text_IO.Put("*"); -- Print "*" for each 250
	    Total_Remaining := Total_Remaining - 250.0;
	 end loop Star_Loop;
	 Text_IO.New_Line;
   end Print_Data;
------------------------------------------------

begin
   Text_IO.Open (File => Popcorn_Data,
                 Mode => Text_IO.IN_FILE,
                 Name => "data.in");
   Print_Header;
  -- Name := "                             ";
   Popcorn_Loop:
      loop
	 exit Popcorn_Loop when Text_IO.End_Of_File(Popcorn_Data);
	 Get_Data   (Data_File => Popcorn_Data,
		     Pints_Per_Acre => Result,
		     Plant_Name => Name);
	 Print_Data (Total => Result,
		     Pints_Per_Acre => Result,
		     Plant_Name => Name);
      end loop Popcorn_Loop;
	 Text_IO.New_Line;
end Graph2;





             reply	other threads:[~1996-07-31  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-31  0:00 Michael W. Hall [this message]
1996-08-01  0:00 ` File Problem. Please help Michael W. Hall
1996-08-01  0:00   ` John Herro
1996-08-03  0:00     ` Michael W. Hall
replies disabled

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