I am self-teaching myself the Ada Programming language and in the text book I am using there is an exercise to print out the factorial value of a number entered by the user. My program compiles and does run fine and I do get the expected output, but if I type in the value of 13, the program crashes and raises an error.
I have no idea why the number 13 does this. Is it an error with the IDE (I use GNAT Studio) and I currently use the Ada 2012 standard. Here is my code:
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;
-- procedure main - begins the program
procedure main is
counter : Integer := 1;
number : Integer := 0;
factorial : Integer := 1;
begin
New_Line;
while counter <= 5 loop
Put("Enter an integer: ");
Get(number);
for Count in 1 .. number loop
factorial := factorial * Count;
end loop;
Put_Line("Factorial value is: " & integer'image(factorial));
factorial := 1;
counter := counter + 1;
end loop;
New_Line;
end main; -- end procedure main
Error Message is this: raised CONSTRAINT_ERROR : main.adb:35 overflow check failed [2021-04-11 13:25:10] process exited with status 1, elapsed time: 02.07s
It seems like such a small issue, but I would just be interested to know if there is something wrong with the code that is creating this, or is it just a general bug with the software I use.
Thank you in advance.