How to resolve the algorithm User input/Text step by step in the Ada programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm User input/Text step by step in the Ada programming language

Table of Contents

Problem Statement

Input a string and the integer   75000   from the text console. See also: User input/Graphical

Let's start with the solution:

Step by Step solution about How to resolve the algorithm User input/Text step by step in the Ada programming language

Source code in the ada programming language

function Get_String return String is
  Line : String (1 .. 1_000);
  Last : Natural;
begin
  Get_Line (Line, Last);
  return Line (1 .. Last);
end Get_String;

function Get_Integer return Integer is
  S : constant String := Get_String;
begin
  return Integer'Value (S);
  --  may raise exception Constraint_Error if value entered is not a well-formed integer
end Get_Integer;


My_String  : String  := Get_String;
My_Integer : Integer := Get_Integer;


with Ada.Text_IO, Ada.Integer_Text_IO;

procedure User_Input is
   I : Integer;
begin
   Ada.Text_IO.Put ("Enter a string: ");
   declare
      S : String := Ada.Text_IO.Get_Line;
   begin
      Ada.Text_IO.Put_Line (S);
   end;
   Ada.Text_IO.Put ("Enter an integer: ");
   Ada.Integer_Text_IO.Get(I);
   Ada.Text_IO.Put_Line (Integer'Image(I));
end User_Input;


with
  Ada.Text_IO,
  Ada.Integer_Text_IO,
  Ada.Strings.Unbounded,
  Ada.Text_IO.Unbounded_IO;

procedure User_Input2 is
   S : Ada.Strings.Unbounded.Unbounded_String;
   I : Integer;
begin
   Ada.Text_IO.Put("Enter a string: ");
   S := Ada.Strings.Unbounded.To_Unbounded_String(Ada.Text_IO.Get_Line);
   Ada.Text_IO.Put_Line(Ada.Strings.Unbounded.To_String(S));
   Ada.Text_IO.Unbounded_IO.Put_Line(S);
   Ada.Text_IO.Put("Enter an integer: ");
   Ada.Integer_Text_IO.Get(I);
   Ada.Text_IO.Put_Line(Integer'Image(I));
end User_Input2;


  

You may also check:How to resolve the algorithm Narcissistic decimal number step by step in the COBOL programming language
You may also check:How to resolve the algorithm Number reversal game step by step in the HicEst programming language
You may also check:How to resolve the algorithm Knapsack problem/0-1 step by step in the Tcl programming language
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the VTL-2 programming language
You may also check:How to resolve the algorithm 100 prisoners step by step in the FOCAL programming language