ADA Program to print a integer number entered by user

Program

With Gnat.IO; use Gnat.IO;
procedure gnatioint is
    I : Integer;
begin
    Put ("Enter an integer: ");
    Get (I);
    Put ("You entered: ");
    Put (I);
    New_Line;
end;

This Ada program reads an integer input from the user and prints it.

  1. With Gnat.IO; use Gnat.IO;

    • This imports the Gnat.IO package, which provides input/output functionalities.
    • The use Gnat.IO; statement allows direct use of functions like Put and Get without prefixing them with Gnat.IO..
  2. procedure gnatioint is

    • Defines a procedure named gnatioint, which acts as the main function.
  3. I : Integer;

    • Declares an integer variable I to store the user input.
  4. begin

    • Marks the start of the execution block.
  5. Put ("Enter an integer: ");

    • Prints the message "Enter an integer: " to prompt the user.
  6. Get (I);

    • Reads an integer input from the user and stores it in variable I.
  7. Put ("You entered: ");

    • Prints "You entered: " as part of the output message.
  8. Put (I);

    • Prints the value of the entered integer.
  9. New_Line;

    • Moves the cursor to the next line for better formatting.
  10. end;

    • Marks the end of the program.

Key Features:

  • Uses Gnat.IO: A simple input/output library in Ada.
  • Type-Safe Input Handling: Ensures that only integers are accepted.
  • User-Friendly Output: Prompts and displays user input clearly.

Output

$ gnat make gnatioint.adb 
gcc -c gnatioint.adb
gnatbind -x gnatioint.ali
gnatlink gnatioint.ali
$ ./gnatioint 
Enter an integer: 6
You entered: 6