hello every1
i made a factorial program and the only thing i need to do is to validate:
Whether it is empty or it contains letters
Here's the code:

program factorial;
uses wincrt;

var
   counter:integer;
   number:integer;
   total:longint;

Begin
     write('Enter your number ');
     readln(number);
     total:=1;
     counter:=1;
     while (counter<=number) do
           Begin
                total:=(total*counter);
                counter:=(counter+1)
           end;
     Writeln('Factorial=',total);
end.

any help will be apreciated. Thanks

simple I/O checking... :D

program factorial;
uses wincrt;

var
   counter:integer;
   number:integer;
   total:longint;

Begin
     write('Enter your number ');
     {$I-}   {checking off}
     readln(number);
     {$I+}   {checking on}
     {if the IoResult is not zero then alert the user}
     If (IoResult <> 0)Then Begin
        Write('Wrong char,please just numbers!');
        ReadLn;
     End
     Else Begin
        total:=1;
        counter:=1;
        while (counter<=number) do
              Begin
                   total:=(total*counter);
                   counter:=(counter+1)
              end;
        Writeln('Factorial=',total);
     End;
     ReadLn;
end.
Comments
Looking good

a part not working
when i enter a letter, it displays Wrong char please enter a number! (that's great), but when i enter a number, the program stop working (inactive)

repeat..until loop?

program factorial;
uses wincrt;

var
   counter:integer;
   number:integer;
   total:longint;

Begin
     Repeat
        write('Enter your number: ');
        {$I-}   {checking off}
        readln(number);
        {$I+}   {checking on}
        total:=1;
        counter:=1;
        while (counter<=number) do
              Begin
                   total:=(total*counter);
                   counter:=(counter+1);
                   Write(total,',');
              end;
     WriteLn;
     Until IoResult<>0;
     ReadLn;
end.

its not working
when a letter is entered, an error occur and program terminate. The first one was better, just need to make it work the the message
WRONG CHAR, PLEASE JUST NUMBER! thats all

We need a condition,understand it please.Cause it will a neverending loop.... :'(

program factorial;
uses wincrt;

var
   counter:integer;
   number:integer;
   total:longint;
   n:Byte;

Begin
     n:=0;
     Repeat
        write('Enter your number: ');
        {$I-}   {checking off}
        readln(number);
        {$I+}   {checking on}
        If IoResult <> 0 Then Write('Wrong char,enter number please')
        Else
        total:=1;
        counter:=1;
        while (counter<=number) do
              Begin
                   total:=(total*counter);
                   counter:=(counter+1);
                   Write(total,',');
              end;
     WriteLn;
     n:=n+1;
     Until n=5;
     ReadLn;
end.

I think a TMaskEdit control in Delphi can easily solve your problem if your program is allowed to run as a standard Windows application.

This article has been dead for over six months. Start a new discussion instead.