comp.lang.ada
 help / color / mirror / Atom feed
* Reply Quickly!
@ 1997-05-25  0:00 oliver white
  1997-05-26  0:00 ` Dale Stanbrough
  0 siblings, 1 reply; 2+ messages in thread
From: oliver white @ 1997-05-25  0:00 UTC (permalink / raw)



This is a multi-part message in MIME format.

--------------7426375871CC
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

It is a simple problem, but could someone take a moment to help?
I have written a program for my university assignment, but it seems to
ignore a get_line in line 50 and the program jumps to the next loop,
seemingly of the same structure, which functions normaly. Please reply
in the next few hours :) Please explain in a manner easy for a man, new
to ADA, to understand.

				Oliver

--------------7426375871CC
Content-Type: text/plain; charset=us-ascii; name="Vehical.adb"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Vehical.adb"

WITH Text_Io;
PROCEDURE Vehical IS

--Author: Oliver White
--Date: 19/5/97

--This program is designed to take in data on a car's registration and
--write it to a file for future referance

SUBTYPE Yeartype IS Integer RANGE 1900..2100;
TYPE Choice_Type IS (Register, Display, Help, Quit);

PACKAGE Menu_Io IS NEW Text_Io.Enumeration_Io(Enum => Choice_Type);
PACKAGE Boolean_Io IS NEW Text_Io.Enumeration_Io(Enum => Boolean);
PACKAGE Int_Io IS NEW Text_Io.Integer_Io(Integer);
PACKAGE Flo_Io IS NEW Text_Io.Float_Io(Float);

RegNo : String(1..10);
Name : String(1..30);
Street : String(1..30);
Suburb : String(1..20);
IsCar : Boolean;
Year : Yeartype;
Price : Float;
Menu_Choice : Choice_Type;
Makefile : String(1..50);
Output : Text_Io.File_Type;
Input : Text_Io.File_Type;
Last_RegNo : Natural;
Last_Name : Natural;
Last_Street : Natural;
Last_Suburb : Natural;
LastFile : Boolean := False;
Last_Makefile : Natural;

PROCEDURE Register IS
	--A subprogram to get data and write it to a file chosen by the user

      
      LastVehical : Boolean := False;
	
BEGIN	
	File_Loop: --loop until last file to be created
	LOOP
		MakeFile_Val_Loop:
		LOOP
      		Text_Io.Put("Please enter name of file to be created:"); --get the file name                                             
			Text_Io.New_Line;
			Text_Io.Put(">");
			Text_Io.Get_Line(MakeFile, Last_MakeFile);

                  MakeFile_Exception:
			BEGIN
				Text_Io.Create(Input, Text_Io.Out_File, MakeFile(1..Last_Makefile)); -- create file
				EXIT MakeFile_Val_Loop;			
			EXCEPTION
				WHEN Text_Io.Name_Error =>
				Text_Io.Put("Invalid file name");
			END MakeFile_Exception;
		END LOOP MakeFile_Val_Loop;	
				
		
		Vehical_Loop: -- loop untill last record to be entered in file
		LOOP
			RegNo_Val_Loop: 
			LOOP
				RegNo_Exception:
				BEGIN
					Text_Io.Put("Please enter registration number:");
					Text_Io.New_Line;
					Text_Io.Put(">");
					Text_Io.Get_Line(RegNo, Last_RegNo);
					EXIT RegNo_Val_Loop;
					
				EXCEPTION
					WHEN Text_Io.Data_Error =>
					Text_Io.Put("Wrong data type");
				END RegNo_Exception;
			END LOOP RegNo_Val_Loop;
			
			Text_Io.Put(Input, RegNo (1..Last_RegNo));
			
			Name_Val_Loop: 
			LOOP
				Name_Exception:
				BEGIN
					Text_Io.Put("Please enter owner's name:");
					Text_Io.New_Line;
					Text_Io.Put(">");
                    Text_Io.Get_Line(Name, Last_Name);
					EXIT Name_Val_Loop;
					
				EXCEPTION
					WHEN Text_Io.Data_Error =>
					Text_Io.Put("Wrong data type");
				END Name_Exception;
			END LOOP Name_Val_Loop;
			
			Text_Io.Put(Input, Name (1..Last_Name));
			
			Street_Val_Loop: 
			LOOP
				Street_Exception:
				BEGIN
					Text_Io.Put("Please enter owner's street name and number:");
					Text_Io.New_Line;
					Text_Io.Put(">");
                    Text_Io.Get_Line(Street, Last_Street);
					EXIT Street_Val_Loop;
					
				EXCEPTION
					WHEN Text_Io.Data_Error =>
					Text_Io.Put("Wrong data type");
				END Street_Exception;
			END LOOP Street_Val_Loop;
			
			Text_Io.Put(Input, Street (1..Last_Street));
			
			Suburb_Val_Loop: 
			LOOP
				Suburb_Exception:
				BEGIN
					Text_Io.Put("Please enter owner's suburb:");
					Text_Io.New_Line;
					Text_Io.Put(">");
                    Text_Io.Get_Line(Suburb, Last_Suburb);
					EXIT Suburb_Val_Loop;
					
				EXCEPTION
					WHEN Text_Io.Data_Error =>
					Text_Io.Put("Wrong data type");
				END Suburb_Exception;
			END LOOP Suburb_Val_Loop;
			
			Text_Io.Put(Input, Suburb (1..Last_Suburb));
			
			IsCar_Val_Loop: 
			LOOP
				IsCar_Exception:
				BEGIN
					Text_Io.Put("Vehical is car?");
					Text_Io.New_Line;
					Text_Io.Put("Enter true or false.");
					Text_Io.New_Line;
					Text_Io.Put(">");
					Boolean_Io.Get(IsCar);
					EXIT IsCar_Val_Loop;
					
				EXCEPTION
					WHEN Text_Io.Data_Error =>
					Text_Io.Put("Wrong data type");
				END IsCar_Exception;
			END LOOP IsCar_Val_Loop;
			
			Boolean_Io.Put(Input, IsCar);

			
			Year_Val_Loop: 
			LOOP
				Year_Exception:
				BEGIN
					Text_Io.Put("Please enter Year of purchase in form XXXX:");
					Text_Io.New_Line;
					Text_Io.Put(">");
					Int_Io.Get(Year);
					EXIT Year_Val_Loop;
					
				EXCEPTION
					WHEN Text_Io.Data_Error =>
					Text_Io.Put("Wrong data type");
				END Year_Exception;
			END LOOP Year_Val_Loop;
			
			Int_Io.Put(Input, Year);
			
			Price_Val_Loop: 
			LOOP
				Price_Exception:
				BEGIN
					Text_Io.Put("Please enter cost of car in A$:");
					Text_Io.New_Line;
					Text_Io.Put(">");
					Flo_Io.Get(Price);
					EXIT Price_Val_Loop;
					
				EXCEPTION
					WHEN Text_Io.Data_Error =>
					Text_Io.Put("Wrong data type");
				END Price_Exception;
			END LOOP Price_Val_Loop;
			
			Flo_Io.Put(Input, Price);

                  LastVehical_Val_Loop:
                  LOOP
                  	LastVehical_Exception:
      	            BEGIN
                		Text_Io.Put("Was this the last vehical entry for this file?");
                        Text_Io.New_Line;
                        Text_Io.Put("Enter true or false.");
                        Text_Io.New_Line;
                        Text_Io.Put(">");
                        Boolean_Io.Get(LastVehical);
                        EXIT LastVehical_Val_Loop;

				EXCEPTION
					WHEN Text_Io.Data_Error =>
                    Text_Io.Put("Wrong data type");
                END LastVehical_Exception;						
			END LOOP LastVehical_Val_Loop;
		
			IF LastVehical = True THEN
				EXIT Vehical_Loop;
			END IF;
					
		END LOOP Vehical_Loop;
		
            Text_Io.Close(Input);
            
		LastFile_Val_Loop:
		LOOP
			LastFile_Exception:
			BEGIN
				Text_Io.Put("Was this the last file to be created?");
				Text_Io.New_Line;
				Text_Io.Put("Enter true or false");
				Text_Io.New_Line;
				Text_Io.Put(">");
				Boolean_Io.Get(LastFile);
				EXIT LastFile_Val_Loop;
			EXCEPTION
				WHEN Text_Io.Data_Error =>
				Text_Io.Put("Wrong data type");
			END LastFile_Exception;
		END LOOP LastFile_Val_Loop;
		
		IF LastFile = True THEN
			EXIT File_Loop;
		END IF;	
	
	END LOOP File_Loop;		
END Register;	


PROCEDURE Display IS  --A procedure for displaying data previously written to a file

NewCar : Natural := 0;
Price_Total : Float := 0.0;
Stop : String (1..1);
Last_Stop : Natural;
Countcar : Natural := 0;
Ave_Price : Float;
NextFile : Boolean;
Current_Year : YearType := 1997;
GetFile : String(1..50);
Last_GetFile : Natural;

BEGIN

	File_Loop:
	LOOP
	
		GetFile_Val_Loop:
		LOOP
			GetFile_Exception:
			BEGIN
				Text_Io.Put("Enter Filename:");
				Text_Io.New_Line;
				Text_Io.Put(">");
				Text_Io.Get_Line(GetFile, Last_GetFile);
				Text_Io.Open(Output, Text_Io.In_File, GetFile(1..Last_GetFile));
			EXCEPTION
				WHEN Text_Io.Name_Error	=>
				Text_Io.Put("File does not exist");
			END GetFile_Exception;
		END LOOP GetFile_Val_Loop;
		
		File_Read_Loop:
		LOOP
			EXIT File_Read_Loop WHEN Text_Io.End_Of_File(Input);
			
			Text_Io.Get_Line(RegNo, Last_RegNo);
			Text_Io.Get_Line(Name, Last_Name);
			Text_Io.Put(Name (1..Last_Name));
			Text_Io.Skip_Line;
			Text_Io.New_Line;
			Text_Io.Get_Line(Suburb, Last_Suburb);
			Text_Io.Put(Suburb (1..Last_Suburb));
			Text_Io.Skip_Line;
			Int_Io.Get(Year);
			
			IF Current_Year - Year < 10 THEN
				NewCar := NewCar + 1;
			END IF;
				
			Flo_Io.Get(Price);
						
			Price_Total := Price_Total + Price;
		
			Text_Io.Put("Press Enter to procede");
			Text_Io.Get_Line(Stop, Last_Stop);
			
			Countcar := Countcar + 1;	
		END LOOP File_Read_Loop;
		
		Text_Io.Put("Number of cars less than 10 yrs old: ");
		Int_Io.Put(Newcar);
		Text_Io.New_Line;
		Text_Io.Put("Average price of vehical: ");
		Ave_Price := Price_Total / Float(Countcar);
		Flo_Io.Put(Ave_Price);
		Text_Io.New_Line;
		
		NextFile_Val_Loop:
		LOOP
			NextFile_Exception:
			BEGIN	
				Text_Io.Put("Would you like to look at another file?");
				Text_Io.New_Line;
				Text_Io.Put("Please answer true or false");
				Text_Io.New_Line;
				Text_Io.Put(">");
				Boolean_Io.Get(NextFile);
				EXIT NextFile_Val_Loop;
			EXCEPTION
				WHEN Text_Io.Data_Error =>
				Text_Io.Put("Wrong data type");
			END NextFile_Exception;
		END LOOP NextFile_Val_Loop;
					
		IF NextFile = False THEN 
			EXIT File_Loop;
		END IF;
	END LOOP File_Loop;
				
END Display;

BEGIN
		
	Main_Loop:
	LOOP
		      
	    Text_Io.Put("*************************");
		Text_Io.New_Line;
		Text_Io.Put("*           Menu        *");
		Text_Io.New_Line;
		Text_Io.Put("* Type HELP to get help *");
		Text_Io.New_Line;
		Text_Io.Put("*************************");
		Text_Io.New_Line;
		
			Choice_Loop:
			LOOP
				Choice_Exception:
				BEGIN
					Text_Io.Put(">");
		      		Menu_Io.Get(Menu_Choice); --Choose task to perform
					EXIT Choice_Loop;
				EXCEPTION
				WHEN Text_Io.Data_Error =>
					Text_Io.Put("Type HELP to learn comands");
				END Choice_Exception;
			END LOOP Choice_Loop;	
			
			IF Menu_Choice = Register THEN
				Register;
			ELSIF Menu_Choice = Display THEN
				Display;		
			--ELSIF Menu_Choice = Help THEN
				--Help;
			ELSIF Menu_Choice = Quit THEN
				EXIT Main_Loop;
            END IF;
	END LOOP Main_Loop;

END Vehical;
			
		 		
			
	

--------------7426375871CC--





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

* Re: Reply Quickly!
  1997-05-25  0:00 Reply Quickly! oliver white
@ 1997-05-26  0:00 ` Dale Stanbrough
  0 siblings, 0 replies; 2+ messages in thread
From: Dale Stanbrough @ 1997-05-26  0:00 UTC (permalink / raw)



oliver white writes:

"SUBTYPE Yeartype IS Integer RANGE 1900..2100;
 TYPE Choice_Type IS (Register, Display, Help, Quit);
 
 PACKAGE Menu_Io IS NEW Text_Io.Enumeration_Io(Enum => Choice_Type);
 PACKAGE Boolean_Io IS NEW Text_Io.Enumeration_Io(Enum => Boolean);
 PACKAGE Int_Io IS NEW Text_Io.Integer_Io(Integer);
 PACKAGE Flo_Io IS NEW Text_Io.Float_Io(Float);"


I wonder whose textbook Oliver uses! :-)

Just a couple of notes...

 PACKAGE Int_Io IS NEW Text_Io.Integer_Io(Integer);
 PACKAGE Flo_Io IS NEW Text_Io.Float_Io(Float);"

can be replaced by 

	with Ada.Text_IO;
	with Ada.Float_Text_IO;

in the context clause.

Also I don't teach the use of enumeration IO for interaction with the
user. I would _never_ write a program like that, and would not expect
my students to either.


Dale




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

end of thread, other threads:[~1997-05-26  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-25  0:00 Reply Quickly! oliver white
1997-05-26  0:00 ` Dale Stanbrough

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